Before randomly accessing a file, it has to be opened. While creating a RandomAccessFile object, you have to specify whether you want to read or read and write.
Java Code:
RandomAccessFile raf = new RandomAccessFile("file.txt", "r");
RandomAccessFile raf2 = new RandomAccessFile("file2.txt", "rw");
After opening the file, readXXX() or writeXXX() methods are used to perform I/O on the file.