How to handle "EOFException" in java

How to handle “EOFException” in java.

1 Like

DataInputStreams provide methods that can read primitive Java data types from an underlying input stream in a machine-independent way. An application writes data, by using the methods provided by the OutputStream class, or the DataOutputStream class.

Once the EOFException is thrown, we only have to break from the reading loop and then, close the stream.