import java.io.*;

public class RandomAccess {
   public static void main(String[] args) throws IOException{
	
      // Create a random access file for reading and writing
      File f = new File("test.out");
      RandomAccessFile theFile = new RandomAccessFile(f,"rw");

      // Write a number of strings to this file.
      theFile.writeBytes("1 3 5");	

	

      long filelength = theFile.length();
      System.out.println("File Length is " +  filelength);

      // Display all the enteries

      theFile.seek(0);
      for (int i = 0; i < 4; i++) {
        System.out.println("Value " + i + " : " + theFile.readLine());   
      }

      // Display the 5th entry  
      theFile.seek(1);
      theFile.writeBytes("2");
      theFile.seek(3);
      theFile.writeBytes("4");
      long j = theFile.getFilePointer();
      System.out.println(j);
      theFile.seek(0);
      for (int ii = 0; ii < 4; ii++) {
         System.out.println("Value " + ii + " : " + theFile.readLine());
      }

      theFile.seek(21);
      theFile.writeBytes("welcome again");

      theFile.close();	    
   }
}


