我们继续运行此错误。目标是将数组中的数据读取到输出文件中。谢谢您的帮助!未报告的异常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