When will an EOFException occur in JAVA's streams

前端 未结 5 729
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:39

    When you reach the end of a stream (end of file, or peer closes the connection):

    • read() returns -1
    • readLine() returns null
    • readXXX() for any other X throws EOFException.

    The stream is still open, but you should stop reading from it and close it.

提交回复
热议问题