当文件存在时,File.exists()返回false [英] File.exists() returns false when file exists

查看:5495
本文介绍了当文件存在时,File.exists()返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个错误,我似乎无法找到任何背后的逻辑。我有这个File对象,它是这样创建的:

$ p $ File file = new File(utilities / data / someTextFile.txt );

然后执行 file.exists() ,并返回 false (!?)。如果找不到文件,我将 f.getAbsolutePath()记录到文件中。当我看着路径,似乎没问题。我可以将完整的路径复制粘贴到Windows的运行窗口中,并且文件可以正常打开。

该文件始终存在,在运行应用程序时不会被删除或更改。它位于本地机器。



这似乎只在某些情况下发生。我可以在任何时候重现错误,但是我确定文件对象的路径不会被我重现错误的操作所改变。



什么可以导致 file.exists()返回false?这是否与权限或文件锁定等有关?

解决方案

我在Windows 7上看到以下情况:

  file.exists()== false 
file.getAbsoluteFile()。exists()== true

有问题的文件是var \log,绝对路径指的是现有的文件在一个正常的子目录(不是一个虚拟商店)。这是从IDE中看到的。


I've encountered a bug I can't seem to find any logic behind. I have this File object, which is created like this:

File file = new File("utilities/data/someTextFile.txt");

I then do file.exists(), and it returns false (!?). If the file is not found, I'm logging f.getAbsolutePath() to a file. When I look at the path, it seems OK. I can copy-paste the complete path into the "Run"-window in Windows and the file opens fine.

The file exists at all times and is not deleted nor changed during the running of my application. It is located at the local machine.

This only seems to occur in certain situations. I can reproduce the fault at any time, but I'm sure the path of the file object is not changed by the actions I make to reproduce the fault.

What can cause file.exists() to return false? Does this have something to do with permissions or file locks, etc.?

解决方案

I am seeing the following situation on Windows 7:

file.exists() == false
file.getAbsoluteFile().exists() == true

The file in question is "var\log", the absolute path does refer to an existing file that is in a normal subdirectory (not a virtual store). This is seen from the IDE.

这篇关于当文件存在时,File.exists()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆