Java:为什么即使路径完整,使用 file.exists() 也会给出错误值?
Java: why using file.exists() is giving a false value even tho the path is complete?
嗯,我刚开始使用 File
,但遇到了问题
我的代码:
File file = new File("D:\File\TextFile.txt");
System.out.println(file.exists());
输出:
假
虽然我已经在该目录中找到了文件!
我发帖后就发现了问题。
事实证明,我的 windows 配置为隐藏扩展名,因此正确的文件名是:
D:\File\TextFile.txt.txt
嗯,我刚开始使用 File
,但遇到了问题
我的代码:
File file = new File("D:\File\TextFile.txt");
System.out.println(file.exists());
输出: 假
虽然我已经在该目录中找到了文件!
我发帖后就发现了问题。 事实证明,我的 windows 配置为隐藏扩展名,因此正确的文件名是:
D:\File\TextFile.txt.txt