Code example for RandomAccessFile

Methods: length, readInt, seek

0
      } 
      return result;
    } 
 
    static int readInt(RandomAccessFile file, long offset) throws IOException {
      file.seek(offset);
      return Integer.reverseBytes(file.readInt());
    } 
 
    static void readBytes(RandomAccessFile file, long offset, byte[] result, int length)
        throws IOException { 
      file.seek(offset);
      file.read(result, 0, length);
    } 
  } 
 
  /** 
   * See http://www.pkware.com/documents/casestudies/APPNOTE.TXT 
   * I.  End of central directory record 
   */ 
  private static class EndOfCentralDirectory { 
    private final RandomAccessFile file;
    EndOfCentralDirectory(RandomAccessFile file) throws IOException {
      this.file = file;
      // Check the signature. 
      if (RandomAccessFileUtility.readInt(file, file.length() - ENDHDR) != ENDSIG) {
        throw new IOException("Invalid ENDHDR signature at " + (file.length() - ENDHDR));
      } 
    } 
 
    CentralDirectory getCentralDirectory() throws IOException { 
      // NOTE : Expects that there is no zip-file-comment at the tail of the file