• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Text is not saved in file...WHY ??

 
Sherry Jacob
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I made a simple text editor using Swing. It has only a JTextArea as the main text processor.

I have added a File menu where I can open or save files with the JFileChooser class.

The code I am using to save data from the JTextArea to a text file say abc.txt is as below :



The file is being created with the specified name but no text is being saved in it even though there is valid text in the JTextArea textPad.

Can anyone help me as to where the fault lies in the code ?

Thanks alot.
[ December 05, 2005: Message edited by: Sherry Jacob ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the write, you need a pw.close(), which will flush any buffered data to the file.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, do you know that text components inherit a write(Writer) method
from JTextComponent? (There's also no need for that intervening StringBuffer)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic