RandomAccessFile class lets you read or write data anywhere in a file. Disk files are random-access, but streams of data from a network are not. You can open a random-access file either for reading only or for both reading and writing; specify the option by using the string
"r" (for read access) or
"rw" (for read/write access) as the second argument in the constructor.
RandomAccessFile in = new RandomAccessFile("employee.dat", "r"); RandomAccessFile inOut = new RandomAccessFile("employee.dat", "rw");
When you open an existing file as a
RandomAccessFile, it does not get deleted.
A random-access file has a file pointer that indicates the position of the next byte to be read or written. ...