Java – File.exists() returns false when file exists


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.?

Best Solution

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.