Tutorial

Showing an open dialog

final VFSJFileChooser m_chooser = new VFSJFileChooser();
m_chooser.setAccessory(new DefaultAccessoriesPanel(m_chooser));
m_chooser.setFileHidingEnabled(false);
m_chooser.setMultiSelectionEnabled(false);
m_chooser.setFileSelectionMode(VFSJFileChooser.FILES_ONLY);

int answer = m_chooser.showOpenDialog(null);

if (answer == VFSJFileChooser.APPROVE_OPTION)
{
 System.out.println("You selected:" + m_chooser.getSelectedFile());
}

Reading a file contents

The return type of the component is a FileObject. You can easily read the file contents by getting an inputstream from it.

// Record it somewhere (ie. as a class member of some class)
// You might need it, if you want to write back the file
FileObject fo = m_chooser.getSelectedFile();   
FileContent content = fo.getContent();
InputStream is = new BufferedInputStream(content.getInputStream());

Saving back the file

FileContent content = fo.getContent();
OutputStream is = new BufferedOutputStream(content.getOutputStream());

Hiding the user credentials(remote connection)

By default the filename value contains the authentication credentials of the opened session. You can hide the password information in your application this way:

String filename = VFSUtils.getFriendlyName(fo.getName().toString());

The demo class

There is a demo(Main.java) in the sources code. It is located under the package net.sf.vfsjfilechooser.demo

If you use Netbeans as Java IDE, you can open directly the project from the extracted archive and run the main class. If you have Apache Ant installed, go into the main folder of the extracted archive and type : ant run.