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

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.