In this example we are going to see how to use JFileChooser Getting And Setting The Current Directory.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import java.io.File; import javax.swing.JFileChooser; public class Main { public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f); chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); File curDir = chooser.getCurrentDirectory(); } } |
Output: