Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to recognize end of file (EOF)?  RSS feed

 
Alan H
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am opening a file for reading:
BufferedReader in = new BufferedReader(new FileReader("test.txt"));
.....
String line = in.readLine();
Can anybody tell me how to recognize the end of file? Because there are some blank lines between text lines, I could not use:
while( line != null){...}
I am newer. Thank you for your help.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While will work, a blank line returns an empty string and not a null. Try the following :

Hope This Helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!