As part of a quality outreach, some changes are coming in the planned Java 25 release with regard to file operations on Windows. The File.delete
command will no longer delete read-only files on Windows, and file operations on a path with a trailing space in a directory or file name will now fail consistently on Windows.
In a June 16 bulletin on Oracle’s inside.java blog, David Delabassee, Oracle director of Java relations, said File.delete
in JDK 25 has been changed on Windows so it now fails and returns false
for regular files when the DOS read-only attribute is set. Before JDK 25, File.delete
would delete read-only files by removing the DOS read-only attribute before deletion was attempted. But because removing the attribute and deleting the file are not a single atomic operation, this could result in the file remaining, with modified attributes. Applications that depend on the previous behavior should be updated to clear the file attributes before deleting files, Delabassee said.
To make the transition easier, a system property has been introduced to restore the previous behavior. Running File.delete
with -Djdk.io.File.allowDeleteReadOnlyFiles=true
will remove the DOS read-only attribute prior to deleting the file, restoring the legacy behavior.