Nicolai Parlog 11/3/2025

Consistent Behavior of new File("")

Read Original

This article discusses a behavioral change in JDK 25 where the File constructor with an empty string now consistently represents the current user directory, fixing an inconsistency present in JDK 24 and earlier. Previously, new File("") appeared non-existent while its absolute path referred to the current directory. The article covers the old behavior, the new consistent behavior, and migration considerations for code relying on the old behavior, such as unit tests or input validation. It also notes that the newer java.nio.file API already handled this correctly.

Consistent Behavior of new File("")

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet