• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for EOF  RSS feed

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the following java idiom:
BufferedReader in = new BufferedReader(new FileReader("foo.in"));
Using the 'in' reference, how can I detect an 'end of file' condition.
Thanks,
 
Jon Dornback
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both read() and read(char[], int, int) return an int that is the number of bytes read. if -1 is returned, the end of the stream has been reached.
readLine() returns null if end of stream has been reached. API for java 1.4 is here:
http://java.sun.com/j2se/1.4/docs/api/java/io/BufferedReader.html

(added code snippet)
[ August 06, 2002: Message edited by: Jon Dornback ]
[ August 06, 2002: Message edited by: Jon Dornback ]
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jon,
So in my case I would check for:

I guess I am still thinking C and the feof() function
Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Standard idioms here are

or

[ August 06, 2002: Message edited by: Jim Yingst ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!