从FileNotFoundException获取文件的文件名(Get the filename of the file from FileNotFoundException)

编程入门 行业动态 更新时间:2024-10-10 11:22:00
从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)

更多推荐

本文发布于:2023-07-27 15:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   文件   FileNotFoundException   filename   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!