我們繼續運行此錯誤。目標是將數組中的數據讀取到輸出文件中。謝謝您的幫助!未報告的異常java.io.FileNotFoundException;必須被捕或宣佈被拋出6
public static void save(Salesperson[] array)
{
PrintStream outfile = null;
try
{
outfile = new PrintStream(new FileOutputStream("data.txt"));
}
catch(FileNotFoundException e)
{
JOptionPane.showMessageDialog(null,"The file could not be created.");
}
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
for(int k = 0; k < array.length; k++)
{
System.out.println(array[k]);
}
outfile.close();
System.out.println("Saved.");
}
好的,那麼你對此有何瞭解?我似乎很清楚。您對檢查的異常有多少了解?你真的*需要重定向'System.out'嗎? (爲什麼不直接寫入文件,沒有重定向?) – 2013-05-11 15:47:25
閱讀[關於異常的Java教程](http://docs.oracle.com/javase/tutorial/essential/exceptions/)或Java入門書。 – 2013-05-11 15:51:04