• Post Reply Bookmark Topic Watch Topic
  • New Topic

end of file question  RSS feed

 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'd like to know what are the ways of checking the end of file.
except:

thank you for any advice
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, readLine() is a BufferedReader method (Or LineNumberReader). For other Readers, InputStreams and Channels, the standard way to detect an end-of-stream is when the read() method returns -1. This method could be read(byte[]), read(char[]), read(ByteBuffer), or something similar, depending on the specific class used.
There are a few other IO classes that have their own special ways to indicate end of stream. A DataInputStream or RandomAccessFile throws EOFException if one of its methods attempts to read bytes that aren't there. There may be others I'm forgetting; if you have a need to use a particular class, read its documentation to see how it indicates EOF. But most use the standard return value of -1.
[ August 16, 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!