Legacy java.io.File and new FileSystems

Alan Bateman Alan.Bateman at oracle.com
Tue Aug 10 13:54:35 PDT 2010


> I've just started looking at some of the new jdk7 API's and am unsure 
> about something.
> Is there anyway legacy java.io.File can use a new user provided 
> FileSystem?
> I have seen the argument that it would of been difficult to impossible 
> to retrofit a lot of the new features to the File class so it was 
> moved to the Path class.
> But is this also true of the FileSystem API?
> Is there some way it can be indicated that a legacy java.io.File 
> instance should use a new alternate FileSystem instead of the platform 
> provided?
java.io.File wasn't really designed to be extended (it probably should 
have been final but we can't change that now). So to your question, you 
can think of File objects as being associated with the default provider 
-- ie: for File f, then f.toPath().getFileSystem() will return the 
default FileSystem. To use the provider mechanism and other file system 
types requires using the new API.

-Alan.


More information about the nio-discuss mailing list