NIO Path method to get canonicalized pathname of a non-existing file

Alan Bateman Alan.Bateman at oracle.com
Fri Oct 21 06:46:56 UTC 2016


On 18/10/2016 16:07, Wang Weijun wrote:

> With java.io.File, one can call getCanonicalPath() to resolve symlinks (of a directory) even if the file does not exist. With the NIO Path, it seems toRealPath() only works for an existing file, is there a similar method to do this?
There isn't an equivalent, mostly because there isn't a real path for a 
file that does not exist. You can build on toRealPath to do what you 
want but as per legacy getCanonicalPath then you cannot predict what the 
path will be when the file is created.

-Alan


More information about the nio-dev mailing list