我想在我的java应用程序发生文件异常时获取不存在的文件的文件名,以便我可以给用户一个短消息。
catch (FileNotFoundException e) {
/* what code to put here to get the filename of the file */
}
最佳答案
这应该显示不存在的文件路径:
try {
//access file
} catch(FileNotFoundException e) {
System.out.println(e.getMessage());
}
输出,用于使用 new Scanner(new File("C:/filetest"))
创建 Scanner
:
C:\filetest (The system cannot find the file specified)
关于java - 从 FileNotFoundException 获取文件的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35988499/