abstract paths

Alan Bateman Alan.Bateman at Sun.COM
Thu Jul 17 11:45:19 PDT 2008


Alan Snyder wrote:
> The kind of abstractness I am referring to is lack of binding to a 
> provider.
>
> Consider two file systems of the same kind (e.g. Windows) accessed 
> through different providers (native file system and FTP). The same 
> fully qualified absolute path can be used in both cases, but the 
> providers are different, so a regular Path will not work.
>
If you somehow know that the ftp server is on Windows and allows access 
to the complete file system using Windows path syntax then this should 
do it:

Path source = FileSystems.getDefault().getPath("C:\\dir\\foo");
Path target = ftpFileSystem.getPath(source.getRoot().toString());       
for (Path name: source) {           
  target = target.resolve(name.toString());
}
source.copyTo(target);

This isn't as efficient as it might be (as I mentioned in my first 
reply) but should do what you want.

-Alan.


       




More information about the nio-discuss mailing list