Sometimes it is required to randomly access a file. Following code is an example where a file is randomly read.

Java Code:
            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

            // appendind text at the end of file
            ran.writeBytes("This will complete the example");