//Copyright (c) 1999, Art Gittleman //This example is provided WITHOUT ANY WARRANTY either expressed or implied. /* Seek forward and back, and writes and reads * in a random access file. */ import java.io.*; public class RandomAccess { public static void main(String [] args) { try { RandomAccessFile raf = new RandomAccessFile("random.dat", "rw"); for (int i=0; i<10; i++) raf.writeInt(i); raf.seek(20); int number = raf.readInt(); System.out.println("The number starting at byte 20 is " + number); raf.seek(4); number = raf.readInt(); System.out.println("The number starting at byte 4 is " + number); raf.seek(5); number = raf.readInt(); System.out.println("The number starting at byte 5 is " + number); raf.close(); }catch (IOException e) { e.printStackTrace(); } } }