从FileNotFoundException获取文件的文件名(Get the filename of the file from FileNotFoundException)
我想获取在我的java应用程序中发生文件异常时不存在的文件的文件名,以便我可以向用户发送短消息。
catch (FileNotFoundException e) { /* what code to put here to get the filename of the file */ }I want to get the filename of the file that do not exist when a file exception occur in my java application so that i can give a short message to the user.
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 new Scanner(new File("C:/filetest")) :
C:\ filetest(系统找不到指定的文件)
This should display the non-existing file path:
try { //access file } catch(FileNotFoundException e) { System.out.println(e.getMessage()); }Output, for creating a Scanner with new Scanner(new File("C:/filetest")):
C:\filetest (The system cannot find the file specified)
更多推荐
发布评论