import java.io.*; public class RandomAccessFileTest { public static void main(String[] args) throws Exception { String homedir = System.getProperty("user.home"); File dbdir = new File(homedir, "testdb"); File dbfile = new File(dbdir, "testfile"); RandomAccessFile f = new RandomAccessFile(dbfile, "rw"); f.seek(20); f.writeInt(345); String s = "xyz"; byte[] sbytes = s.getBytes(); int slen = sbytes.length; f.seek(40); f.writeInt(slen); f.write(sbytes); f.seek(20); System.out.println("value at location 20 = " + f.readInt()); f.seek(40); int newslen = f.readInt(); byte[] b = new byte[newslen]; f.read(b); String s2 = new String(b); System.out.println("value at location 40 = " + s2); } }