*
The moose likes Swing / AWT / SWT and the fly likes Text is not saved in file...WHY ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Text is not saved in file...WHY ??" Watch "Text is not saved in file...WHY ??" New topic
Author

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

Sherry Jacob
Ranch Hand

Joined: Jun 29, 2005
Posts: 128
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 ]

<strong><br />Cheers !!<br /> <br />Sherry<br /></strong><br />[SCJP 1.4]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

After the write, you need a pw.close(), which will flush any buffered data to the file.


[Jess in Action][AskingGoodQuestions]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Also, do you know that text components inherit a write(Writer) method
from JTextComponent? (There's also no need for that intervening StringBuffer)


There is no emoticon for what I am feeling!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Text is not saved in file...WHY ??
 
Similar Threads
Creating a new file using PrintWriter.
Cant save a text file
how to get the info from a jtextarea
Preserve format of JTextArea in Text file
how to get the info from a jtextarea