I have a save dialog box that seems to work except for a couple issues:
when the save dialog first opens I want a default filename "testing.txt" to
appear in the filename field. How do I make this happen?
(currently trying "setSelectedFile(new File("FileName"));", but no luck yet)
How can I make the file ALWAYS save as .txt by default?
String messageCont = outTextArea.getText();
/*create file chooser*/
final JFileChooser fc = new JFileChooser();
/*attache the file chooser to the Frame and detect OK or Cancel*/
int returnVal = fc.showSaveDialog(HanoiFrame.this);
//fc.setSelectedFile();
File file = fc.getSelectedFile();
//File file = fc.setSelectedFile(new File("testing.txt"));
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
/*if OK write the file*/
BufferedWriter output = new BufferedWriter(new FileWriter(file.getPath() + file.getName()));
output.write(messageCont);
output.close();
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
/*cancel*/
return;
}
Thanks.