Java tutorial
import java.io.*; 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.writeChars(s); raf.seek(0); for (int i = 0; i < 15; i++) { System.out.println(raf.readChar()); } raf.seek(0); raf.writeChars("This is an example from java2s.com"); raf.seek(0); for (int i = 0; i < 20; i++) { System.out.println(raf.readChar()); } raf.close(); } catch (IOException ex) { ex.printStackTrace(); } } }