aspose file tools*
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
Author

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:


try{
BufferedWriter b = new BufferedWriter(new FileWriter(field1.getText()));
b.write(s);
System.out.println(b);
field2.setText("File has been Written!!");
}catch(Exception e)
{
System.out.println(e);
}

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




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

}catch(EOFException e)
{
System.out.println(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: http://aspose.com/file-tools
 
subject: another File reading problem