Using RandomAccessFile
class, I'm trying to test the concept of writing/reading to/from a file in java. So I tried this code:
public static void main (String[] args) throws IOException {
RandomAccessFile storage = new RandomAccessFile("FILE.txt", "rw");
storage.seek(0);
storage.writeInt(1);
storage.seek(1);
storage.writeInt(2);
storage.seek(2);
storage.writeInt(3);
storage.seek(3);
storage.writeInt(4);
storage.seek(4);
storage.writeInt(5);
System.out.println(storage.readInt());
System.out.println(storage.readInt());
System.out.println(storage.readInt());
System.out.println(storage.readInt());
System.out.println(storage.readInt());
storage.close();
I think it should print : 1 2 3 4 5
but what happens is that it prints: 3 4 5 EOFException... why?