You need to use the setSelectedFile method and pass the file as a parameter. The file must not exist.
If the file path is specified, the file selection will try to point to the file directory, if one exists
JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File("C:\\file.txt")); fileChooser.showSaveDialog(null);
source share