Code example for RandomAccessFile

Methods: readShort, seek

0
      // be applicable here. 
      throw new IllegalAccessError("This class should not instantiated.");
    } 
 
    static short readPositiveShort(RandomAccessFile file, long offset) throws IOException {
      file.seek(offset);
      short result = Short.reverseBytes(file.readShort());
      if (result < 0) {
        throw new IOException(
            "Unexpected negative value ; offset = " + offset + ", value = " + result);
      } 
      return result;
    } 
 
    static int readPositiveInt(RandomAccessFile file, long offset) throws IOException {
      int result = readInt(file, offset);
      if (result < 0) {
        throw new IOException(
            "Unexpected negative value ; offset = " + offset + ", value = " + result);
      } 
      return result;