• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another File reading problem

 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic