File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

Joined: Jul 08, 2003
Posts: 24199

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!
I agree. Here's the link:
subject: Text is not saved in file...WHY ??
It's not a secret anymore!