我正在執行此程序,並且在輸出結束時,我始終收到「null」錯誤,正如您在代碼中看到的一樣。它確實讀取文件,但最後,它增加了很多null。任何指導將不勝感激! 這是我到目前爲止所嘗試的。讀取文件後輸出中的空錯誤
public static void main(String[] args) throws Exception
{
Stack nifo=new Stack();
FileReader file = new FileReader("infix.dat");
try (BufferedReader br = new BufferedReader(file)) {
String [] words = new String[50];
String text="";
int ctrl = 0;
String Line =br.readLine();
while (Line!= null)
{
words[ctrl]= Line;
Line = br.readLine();
ctrl = ctrl + 1;
}//end of while loop
for (int i = 0; i < words.length; i++)
{
System.out.println(words[i]);
}
file.close();
} catch (IOException e) {
e.printStackTrace();
}//end of catch
}//end of main class
我的輸出結果如下。正如你所看到的,在我讀完我的文件後,null會被打印在最後。
5 * 6 + 4
3 - 2 +
(3 * 4 - (2 + 5)) * 4/2
10 + 6 * 11 -(3 * 2 + 14)/2
2 * (12 + (3 + 5) * 2
null
null
null
null
more nulls after that.
謝謝!
這不是錯誤,那是數組中的所有空白空間。 – azurefrog