Class EOFException in Java

Class EOFException in Java

EOFException is popular built-in exception classes in java and is thrown from an application indicating that an end of file has been reached unexpectedly during input.

This exception is mainly used by DataInputStream classes. This class expects a binary file in a specified format and for which the end of the stream is an unusual condition. Most other input Streams return a special value on the end of Streams.

An EOFException is thrown in response to an attempt to read past the end of a file.

Many file-handling routines indicate the end of a file with a special return code. For example, many read() methods return -1 to indicate that the end of file has been reached. However, in some cases, the program clearly expects a certain format of data in a file.

If it’s not all there, throwing an exception is an appropriate way to flag the unusual condition of the file. So, for example, a DataInputStream throws an EOFException if it comes to the end of the file in the middle of readFloat(). In the package, EOFException is used in the classes that implement the DataInput and ObjectInput interfaces, namely DataInputStream, ObjectInputStream, and RandomAccessFile.

The structure of the class EOFException is given as:

public class extends{
public EOFException();
//constructs an empty EOFException object that is an object with no message specified.
public EOFException(String message);
//constructs an EOFException object with the message specified.

The class EOFException also inherits methods from class Object and Throwable.

From Object classFrom Throwable class
wait(long, int)getLocalizedMessage()
See also  Class NotSerializableException in Java

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *