Is there any way to choose a directory and get it adres?
How in the case of JFileChooser can I get the path to the selected file?

1 answer 1

Slightly modified the javadoc example for JFileChooser

 JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.isMultiSelectionEnabled() ? chooser.getSelectedFiles()[0] : chooser.getSelectedFile(); System.out.println("a directory: " + selectedFile.getAbsoluteFile().getParent()); System.out.println("an absolute path: " + selectedFile.getAbsolutePath()); }