如果我註釋掉兩個for循環,程序將運行正常(因爲我調整了一個或兩個變量)。但是,當我在Eclipse中編譯和運行時,它只是坐着,沒有任何溢出錯誤或其他任何東西。該文件是一個文本文件,我試圖根據哪些行中包含*字符來過濾掉這些文件。爲什麼此功能無法正常工作,但在Eclipse中不顯示錯誤?
public List<String> readFile1(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
//Construct BufferedReader from InputStreamReader
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
List<String> list = new ArrayList<>();
String line = null;
String checker = null;
int whereMenuItemIs = 0;
while ((line = br.readLine()) != null) {
if(!line.startsWith("\u0009")) {
for(int i=0; i<getListFromFile("C:/IRT", "bios.txt").size(); i++)
{
if(getListFromFile("C:/IRT", "bios.txt").get(i).contains(line))
{
i = whereMenuItemIs;
}
}
for(int j=whereMenuItemIs+1; j<getListFromFile("C:/IRT", "bios.txt").size(); j++)
{
if(readFile1(file).contains(getListFromFile("C:/IRT", "bios.txt").get(j)))
{
System.out.println("it got here");
}
else
{
checker= checker + getListFromFile("C:/IRT", "bios.txt").get(j);
}
}
if(checker.contains("\u0009*")){
}
list.add(line);
}
}
br.close();
return list;
}
它只是坐在那裏永遠不會退出循環?嘗試在這裏拋出一個打印語句來看看它在讀什麼 – Neverwork2123 2015-02-10 05:12:14
它在這裏被捕獲:for(int i = 0; i
Jordan
2015-02-10 05:17:05
此外,每次進入循環時都不應重讀文件。只需在頂部讀取它並將其轉儲到數組 – 2015-02-10 05:17:07