You can use a JFileChooser
to be able to select a file from a dialog box.
Assuming you want to launch it outside a Java Swing application, you could proceed as next:
final JFileChooser fc = new JFileChooser();
// Open the dialog using null as parent component if you are outside a
// Java Swing application otherwise provide the parent component instead
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
// Retrieve the selected file
File file = fc.getSelectedFile();
try (FileInputStream fis = new FileInputStream(file)) {
// Do something here
}
}
More details about How to Use File Choosers