How to use RandomAccessFile class?
This is an example of using
RandomAccessFile class to read and write data to a file. Using
RandomAccessFile enable us to read or write to a specific location in the file at the file pointer. Imagine the file as a large array of data that have their own index.
In the code below you'll see how to create an instance of
RandomAccessFile and define its operation mode (read / write). After we create an object we write some data, some book's titles to the file. The last few line of the codes demonstrate how to read file data.
The result of our program are:
The Java Application Programming Interface
Java Security Handbook
Hacking Exposed J2EE & Java
Servlet & JSP Programming