Convert a FileObject into a File

Gleb Belyaev picture Gleb Belyaev · Aug 28, 2013 · Viewed 10.9k times · Source

I'm using Apache Commons VFS2 (Virtual File System) to monitor change file in directory. org.apache.commons.vfs2.FileListener return org.apache.commons.vfs2.FileObject. How Convert a org.apache.commons.vfs2.FileObject into a java.io.File

Answer

laughing_man picture laughing_man · Nov 4, 2013
fileobject.getURL().getFile()

should work. The caveat is that we need to convert it first to a Java URL object, which can then be used to resolve the file.