When will an EOFException occur in JAVA’s streams

The key word is unexpected.

If you use DataInputStream and read a 4 byte integer but there were only 3 bytes remaining in the stream you’ll get an EOFException.

But if you call read() at the end of stream you’ll just get -1 back and no exception.

Leave a Comment