Sometimes it is required to randomly access a file. Following code is an example where a file is randomly read.
File file = new File("file.out");
RandomAccessFile ran = new RandomAccessFile(file, "rw");
byte ch = ran.readByte();
System.out.println("Read first character of file: " + (char)ch);
// reading remaining line
// Prontout text from the current cursor position
System.out.println("Read full line: " + ran.readLine());
// Seek to the end of file
ran.seek(file.length());
// appendind text at the end of file
ran.write(0x0A);
ran.writeBytes("This will complete the example");
ran.close();