Home > Uncategorized > Convert a FileObject into a File

Convert a FileObject into a File

This will be quick, more for my future reference (and hopefully others’ as well) than any real tutorial.

In NetBeans Platform, most IO etc is done with FileObject instances rather than plain Java File objects.  It was not immediately clear how to convert between the two, which is necessary when some APIs require java.io.File objects, and others require the org.openide.filesystems.FileObject instances.  The answer is to use the FileUtil class, which exposes two methods:

static File toFile(FileObject fo)
Finds appropriate java.io.File to FileObject if possible.
static FileObject toFileObject(File file)
Converts a disk file to a matching file object.

Hope this pops up to the top of the google results for “convert a FileObject into a File”.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: