View Single Post
  #1 (permalink)  
Old 07-16-2007, 07:56 PM
paul paul is offline
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
How can I make the file ALWAYS save as .txt by default
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
Code:
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?

Code:
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.
Reply With Quote
Sponsored Links