All -

I am trying to set up a VFS but I struggled a while to get past a 
FileSystemException. After looking at the VFS source code I understood what was 
going on, and I was able to create a work-around. However, I am not sure that 
what I hacked together is the right approach so I am looking for some guidance 
from the experts here…

This is what I was trying to do:

    FileObject path = VFS.getManager().resolveFile("ftp://ftp.gnu.org/README";, 
new FileSystemOptions());

The issue is, or at least appears to be, that the FileSystemManager doesn’t 
have a baseFile so the resolveFile blows up with this exception:

    org.apache.commons.vfs2.FileSystemException: Could not find file with URI 
"ftp://ftp.gnu.org/README"; because it is a relative path, and no base URI was 
provided.
        at 
org.apache.commons.vfs2.FileSystemException.requireNonNull(FileSystemException.java:87)

I could not find how/where to define that baseFile so I eventually settled on 
this work-around:

   StandardFileSystemManager fsManager = (StandardFileSystemManager) 
VFS.getManager(); // YUCK!
   fsManager.setBaseFile(new File("")); // Another YUCK.
   FileObject path = fsManager.resolveFile("ftp://ftp.gnu.org/README";, opts);

That works, and now I end up with the correct (expected) path. It doesn’t feel 
right though so any advice would be greatly appreciated.


Cheers,

Erwin


Reply via email to