答案 0 :(得分:0)
屏幕截图中的错误是未处理的异常编译器错误。
FileNotFoundException
是受检查的异常,因为它源自IOException
。
如果未捕获或抛出异常,则检查后的异常在编译时将始终生成编译器错误。
在throws FileNotFoundException
中添加main
或将代码将其扔到try/catch
块中。
public static void main(String args[]) throws FileNotFoundException
或
Scanner input = null;
try {
input = new Scanner(f);
}
catch {
System.Out.Print("File not found");
return 1;
}
该文件还需要位于资源文件夹中,构建脚本才能复制到目标文件夹中以运行。
我不确定Eclipse,但是我看到的标准是资源文件夹位于src/main/resources
中。
答案 1 :(得分:0)
我现在没有日食,但问题可能出在路径上。试试这个
File f = new File(System.getProperty("user.dir") + "gift1.in");
或
File f = new File("[/absolute/path/to/file]");