有沒有一種方法可以打印出我們在這種情況下無法找到的文件?確定打開兩個文件時我們找不到哪個文件
try{
in1 = new Scanner(new File(inPath1));
in2 = new Scanner(new File(inPath2));
} catch (FileNotFoundException e){
System.err.println("File not found: " e);
System.exit(0);
}
此打印出:
File not found: java.io.FileNotFoundException: test.dat (The system cannot find the file specified)
但我只在文件名,而不是整個字符串感興趣。
你可以把它分成兩個單獨嘗試捕獲 – dbrown93
@ dbrown93是的,這是我的最後一招,但必須有一個更優雅的解決方案。 –