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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » File » RandomAccessFile 
9.2.2.A RandomAccessFile has a file pointer
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class MainClass {
  public byte[] readRecord(int rnthrows 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.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.