Java tutorial
import java.io.*; public class Main { public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF("Hello World"); // set the file pointer at 0 position raf.seek(0); // print the line System.out.println(raf.readLine()); // set the file pointer at 0 position raf.seek(0); raf.writeUTF("This is an example \n Hello World"); raf.seek(0); // print the line System.out.println(raf.readLine()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } } }