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());
}
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());
FileContent content = fo.getContent(); OutputStream is = new BufferedOutputStream(content.getOutputStream());
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());
There is a demo(Main.java) in the sources code. It is located under the package net.sf.vfsjfilechooser.demo