File.getCanonicalPath() and Path.toRealPath()
Alan Bateman
Alan.Bateman at Sun.COM
Sat Jun 27 13:09:24 PDT 2009
Brian Dellisanti wrote:
> Is there any guaranteed relationship between the result of
> File.getCanonicalPath() and the result of Path.toRealPath(true) with
> the default provider?
>
A good question!
If java.io.File f exists, then f.getCanonicalFile().toPath() should be
equal to f.toPath().toRealPath(true). I say "should" because it isn't
guaranteed and you will find cases where it won't hold. For example File
doesn't work with sym links on Windows (yet), or it doesn't preserve the
platform representation of the file path.
-Alan.
More information about the nio-discuss
mailing list