new File(“”) vs. new File(“.”): Feature or Bug?

While using the constructor with the empty String, you create a File instance that has two properties :

  • It does not actually exists.
  • Its absolute pathname is the “empty abstract pathname”

When using File(“.”), you create a different file :

  • It DOES exist on the file system
  • Its absolute pathname contains the “.” character

This second file exists, not the first. The second file is consequently the only one that is supposed to respect the rule explained in getCanonicalPath :

Every pathname that denotes an existing file or directory has a unique canonical form.

As the first file is not real, the fact that their canonical paths are equal is meaningless.

Consequently, the behviour you’ve pointed is not a bug. It’s the one we expected from the JVM.

You’ll find all the infos in the javadoc

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)