两个错误catch
没有try
try
没有catch
,finally
或资源声明
try {
File file = new File("path to file");
Scanner sc = new Scanner(file);
String line;
while (sc.hasNextLine()) {
line = scanner.nextLine();
System.out.println(line);
} catch (FileNotFoundException e) {
System.out.println("Error in input/output");
}
scanner.close();
}
}
}
答案 0 :(得分:2)
catch块必须是try块的 ,不在内部:
try {
File file = new File("path to file");
Scanner sc = new Scanner(file);
String line;
while (sc.hasNextLine()) {
line = scanner.nextLine();
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("Error in input/output");
} finally {
scanner.close();
}