Getting and Setting the Current Directory of a JFileChooser Dialog
JFileChooser chooser = new JFileChooser();
try {
// Create a File object containing the canonical path of the
// desired directory
File f = new File(new File(".").getCanonicalPath());
// Set the current directory
chooser.setCurrentDirectory(f);
} catch (IOException e) {
}
// The following method call sets the current directory to the home directory
chooser.setCurrentDirectory(null);
// Show the dialog; wait until dialog is closed
chooser.showOpenDialog(frame);
// Get the current directory
File curDir = chooser.getCurrentDirectory();
Post a comment