Java tutorial
import java.io.RandomAccessFile; public class Main { public static void main(String[] args) { try { String s = "Hello world from java2s.com"; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF(s); raf.seek(0); System.out.println(raf.readUTF()); raf.seek(0); raf.writeUTF("This is an example from java2s.com"); raf.seek(0); System.out.println(raf.readUTF()); raf.close(); } catch (Exception ex) { ex.printStackTrace(); } } }