I wrote a program to read from a specific file and was wondering how would I display a custom message if that file were to not be found.
(我编写了一个程序来读取特定文件,并且想知道如果找不到该文件该如何显示自定义消息。)
What I have currently does not work, could someone explain why? (我目前没有的东西,有人可以解释为什么吗?)
try {
//create the file writer
Fwrite = new FileWriter(file);
Fwrite.write("Student Name Test Score Grade
");
for (int i = 0; i < size; i++) {
Fwrite.write(students[i].getStudentLName() + ", " + students[i].getStudentFName() +
" "+ students[i].getTestScore() + " " + students[i].getGrade() + "
");
}
Fwrite.write("
Highest Test Score: " + highestScore + "
");
Fwrite.write("Students having the highest test score
");
//writes the test scores in descending order
for (int i = 0; i < size; i++) {
if (students[i].getTestScore() == highestScore) {
Fwrite.write(students[i].getStudentLName() + ", ");
Fwrite.write(students[i].getStudentFName() + "
");
}
}
//catches any errors
} catch (IOException e) {
System.err.println("File mot Found!");
e.printStackTrace();
}
//try catch method to catch any errors
System.out.println("File Complete!");
//close file
Fwrite.close();
ask by ZootZoot translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…