save file with JFileChooser save dialog
I have written a Java program that opens all kind of files with a JFileChooser. Then I want to save it in another directory with the JFileChooser save dialog, but it only saves an empty file. What can I do for saving part? Thanks. JFileChooser just returns the File object, you'll have to open a FileWriter and actually write the contents to it. E.g. if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileWriter fw = new FileWriter(file); fw.write(contents); // etc... } Edit: Assuming that you simply have a source file and destination file and want to copy the