我正在创建一个类——只是一个类,没有 main() 并且我在这一行收到“未报告的异常 java.io.FileNotFoundException; 必须被捕获或声明为抛出”的错误:
FileOutputStream outStr = new FileOutputStream(FILE, true);
我不明白; 我放入了一个 try{} catch{} 块,它仍在报告错误。
此外,它还报告了 try 和 both catch 行的“非法类型开始”,它还说 ';' 预计两条捕获线。
我正在使用 NetBean IDE,仅供参考。
感谢您的任何帮助。
这是完整的代码:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileNotFoundException;
public class UseLoggingOutputStream
{
String FILE = "c:\\system.txt";
try
{
FileOutputStream outStr = new FileOutputStream(FILE, true);
}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.getMessage());
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}