When will an EOFException occur in JAVA's streams

前端 未结 5 730
Happy的楠姐
Happy的楠姐 2020-11-29 11:12

I am working with a DataInputStream and had a question about EOFExceptions.

According to java docs:

Signals that an end of file or end of st

5条回答
  •  我在风中等你
    2020-11-29 11:43

    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.

提交回复
热议问题