Question Details

No question body available.

Tags

java file-io java-25

Answers (1)

Accepted Answer Available
Accepted Answer
February 10, 2026 Score: 28 Rep: 50,336 Quality: Expert Completeness: 80%

From the Java 25 release notes:

core-libs/java.io
java.io.File Treats the Empty Pathname As the Current User Directory (JDK-8024695)

The java.io.File class is changed so that an instance of File created from the empty abstract pathname ("") now behaves consistently like a File created from the current user directory. Long standing behavior was for some methods to fail for the empty pathname. The change means that the canRead, exists, and isDirectory methods return true instead of failing with false, and the getFreeSpace, lastModified, and length methods return the expected values instead of zero. Methods such as setReadable and setLastModified will attempt to change the file's attributes instead of failing. WIth [sic] this change, java.io.File now matches the behavior of the java.nio.file API.

In short, the change seems to have been made to (1) make the behavior consistent between methods of File and (2) make the behavior consistent with the java.nio.file API.

There's been a few bugs opened about this:

The last one suggests possibly deprecating File::exists() and adding a new method with the updated behavior. Though the associated unmerged1 pull request instead adds a jdk.io.File.failIfEmptyPath system property to allow developers to use the old behavior.


1. As of February 9, 2026.