Reputation: 411
Why does this code return false?
Path path = Paths.get("C:\\aaa\\bbb\\ccc");
Files.exists(path); // false!?
Even when I convert to it from a File (which exists):
File file = new File("C:\\aaa\\bbb\\ccc");
file.exists(); // true!!!
Path path = file.toPath();
Files.exists(path); // still false!?
Upvotes: 3
Views: 999
Reputation: 86774
I was able to reproduce this under the following specific circumstances:
I tested this on Linux (Centos 6) and cannot reproduce it even when changing the filemode on the directory (i.e. chmod -x /aaa/bbb/ccc
or chmod -r /aaa/bbb/ccc
)
So this appears to occur only on Windows. There must be some difference between how java.io
and java.nio.file
implement existence testing with regards to file permissions on Windows.
Check the permissions on the directory.
This may be a bug worth reporting.
Upvotes: 5