You may come across code that reads from an InputStream
and uses the snippet
while(in.available()>0)
to check for the end of the stream, rather than checking for an
EOFException (end of the file).
The problem with this technique, and the Javadoc
does echo this, is that it only tells you the number of blocks that can be read without blocking the next caller. In other words, it can return 0
even if there are more bytes to be read. Therefore, the InputStream available()
method should never be used to check for the end of the stream.
You must use while (true)
and
catch(EOFException e) {
//This isn't problem
} catch (Other e) {
//This is problem
}