JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println("Selected file: " + selectedFile.getAbsolutePath()); }This code creates a JFileChooser dialog, sets the current directory to the user's home directory, and shows the dialog to the user. If the user selects a file, the selected file's path is printed to the console. In this example, the JFileChooser component is imported from the javax.swing package, which is part of the Java Standard Library.