File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes another File reading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "another File reading problem" Watch "another File reading problem" New topic

another File reading problem

Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
Now a new problem has occured. Let me just say that im taking the text from a textarea, so its more than one line of text. and im writing to a file like this:

BufferedWriter b = new BufferedWriter(new FileWriter(field1.getText()));
field2.setText("File has been Written!!");
}catch(Exception e)

Then to print the text back on another text area im using this code now:

BufferedReader b;
BufferedReader r = new BufferedReader(new FileReader(field1.getText()));
String ln;
while((ln = r.readLine()) != null)
new FrameSetUp().area2.append(String.format("%s + its working",ln));

}catch(EOFException e)
but all im getting is an EOFexception everytime i try to open the file? i cant figure out whats wrong.

("Anger is not an emotion, its a symptom of fear.")
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Your forgot to flush() and close() the BufferedWriter. That's probably the problem.

Remember always flush your OutputStreams and Writers before closing them.

I hope this helps!
[ March 27, 2006: Message edited by: Edwin Dalorzo ]
I agree. Here's the link:
subject: another File reading problem
It's not a secret anymore!