When will an EOFException occur in JAVA's streams

前端 未结 5 716
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:47

    EOFException is thrown:

    1. if there is no data in a STREAM but you are trying to read...eg read methods of chain streams like DataInputStream, ObjectInputStream, RandomAccessFile throw EOFException if they are trying to read from FileInputStream but the FileInputStream is empty
    2. or if the formats are not matching...eg if int is present and you are using readFloat() of DataInputStream

提交回复
热议问题