Mark Proctor wrote:
What is the most robust way to get an absolute path to the file, so
that I can do new File(path) to access that file? Below seems a bit
flakey, but I can't think of anything better.
String file =
request.getFileSystemView().getCurrentDirectory().getFullName();
User user = request.getUser();
String name = user.getName();
String home = user.getHomeDirectory();
if ( home.startsWith(".") ) {
home = home.substring( 1 );
}
File file = new File( System.getProperty("user.dir") + home + file +
request.getArgument() );
Hey Mark,
I think the following code should work for you. Note that it checks to
see if we're using the native file system. if we're not you pretty
much screwed as there might not be a File at all (it might be a
database record or a JMS message instead).
FileSystemView fsview = session.getFileSystemView();
FileObject theFileObject =
fsview.getFileObject(request.getArgument());
if (theFileObject instanceof NativeFileObject) {
NativeFileObject nativeFileObject = (NativeFileObject)
theFileObject;
File theFile = nativeFileObject.getPhysicalFile();
} else {
// sorry, don't know how to get the file from this type of
file system
}
/niklas