No Path equivalent to File.mkdirs() ?

Alan Bateman Alan.Bateman at Sun.COM
Tue Apr 28 07:23:17 PDT 2009


Rémi Forax wrote:
> Yes, but don't provide it as a utility method will have the following 
> effects:
> - users will not using Path API
> - users will create a File from a Path to call mkdirs()
> - users will create their own code
> So I think it's a good idea to create this helper method in Paths.
If added, then the most appropriate place is as a static method in the 
Files class, something like Files#createFileTree.
>
> By the way, there is also no way to get a File from a Path
> for the default FileSystem.
> So the compatibility between File and Path is only
> in one way. This will  delay the adoption of the Path API.
Yes, it's one way because in general you can't create a Path from a 
File. The idea is that it will be easy to fix existing problems for code 
using java.io.File without too many changes [eg: f.delete() -> 
f.toPath().delete() ]

Going the other way is problematic because it doesn't make sense for 
other custom providers, and even in the case of the default provider, it 
is possible to loose the platform representation.  The Path class 
already has a section in the class description to explain this. If 
needed then it can be done by converting to a string [eg: new 
File(path.toString()) ]. Not clear that we need anything else.

-Alan



More information about the nio-dev mailing list