Java 不知道文件何时不存在
Java知道文件何时存在,因为它会打印出“文件已找到”,但是当文件不存在时,它不会打印“文件未找到”,
File file = new File(filePath, "Test_1.exe");
if (file.exists()){
System.out.println("File found");
}else{
System.out.println("File not found");
}
有人知道为什么吗?文件路径是正确的,因为我已经仔细检查了这一点。只是奇怪的是,如果文件不存在,则不会打印出来,但如果存在,则会打印出来。
我也尝试过 if (!file.exists()) 但不走运!
Java knows when a file exists as it prints out "File found" but when the file does not exists it does NOT print "File not found"
File file = new File(filePath, "Test_1.exe");
if (file.exists()){
System.out.println("File found");
}else{
System.out.println("File not found");
}
does any one know why? the file path is correct as I have double checked this. Just weird that if the file does not exists it wont print out but will if it does.
I have also tried if (!file.exists()) with not luck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
尝试使用文件的完整路径。例如:
来自javadocs:
Try using the full path to the file. eg :
From the javadocs :