Instances of
RandomAccessFile class support both reading and writing to a file. There is a kind of cursor, or index called the file pointer. All read operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read/write mode, then output operations are also available; output operations write bytes starting at the file pointer and advance the file pointer past the bytes written.
The file pointer can be read by the
getFilePointer method and set by the seek method. It is generally true of all the reading routines in this class that if end-of-file is reached before the desired number of bytes has been read, an EOFException (which is a kind of IOException) is thrown. If any byte cannot be read for any reason other than end-of-file, an IOException other than EOFException is thrown. In particular, an IOException may be thrown if the stream has been closed.
Random Access File Demo CODE import java.io.*; OUTPUT Input : Learn Java With Merit Campus DESCRIPTION We created a
|