A RandomAccessFile has a file pointer : RandomAccessFile « File « SCJP






import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class MainClass {
  public byte[] readRecord(int rn) throws IOException {
    RandomAccessFile ranf = new RandomAccessFile("c:\\a.txt","w");
    long fpos = rn * 3;
    ranf.seek(fpos);
    byte[] rec = new byte[3];
    ranf.read(rec);
    return rec;
  }
}








9.2.RandomAccessFile
9.2.1.Create RandomAccessFile from File object
9.2.2.A RandomAccessFile has a file pointer
9.2.3.'long getFilePointer() throws IOException' returns the current position within the file in bytes.
9.2.4.'long length()' throws IOException Returns the length of the file, in bytes.
9.2.5.'void seek(long position) throws IOException' Sets the current position within the file, in bytes.