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.

Ads code goes here

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 java.io 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 java.io.EOFException extends java.io.IOException{
//constructor
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
clone()fillInStackTrace()
getClass()getMessage()
notify()printStackTrace()
wait()printStackTrace(PrintWriter)
wait(long, int)getLocalizedMessage()
wait(long)printStackTrace(PrintStream)
equals(Object)
toString()
finalize()
hashCode()
notifyAll()
READ  Class UnsatisfiedLinkError in Java

Share and Enjoy !

Leave a Comment

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