title: IndexOutofBounds when using Java's read bytes
body: <p>I am using a <a href="http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html" rel="noreferrer">RandomAccessFile</a> in Java 6 but having some strange behavior when reading bytes.</p>
  
  <p>With the following code, where <code>offset</code> and <code>data</code> are appropriately initialized:</p>
  
  <pre><code>int offset;
  byte data[];
  randFile.readFully(data, offset, data.length);
  </code></pre>
  
  <p>I get  the following stack trace:</p>
  
  <pre><code>null
  java.lang.IndexOutOfBoundsException
      at java.io.RandomAccessFile.readBytes(Native Method)
      at java.io.RandomAccessFile.read(RandomAccessFile.java:355)
      at java.io.RandomAccessFile.readFully(RandomAccessFile.java:414)
  </code></pre>
  
  <p>BUT, with the same values of <code>offset</code> and <code>data</code>, the following (seemingly identical) code works fine!</p>
  
  <pre><code>randFile.seek(offset);
  
  for (int i = 0; i &lt; (data.length); i += 1) {
      data[i] = randFile.readByte();
  }
  </code></pre>
  
  <p>Does anybody have insight into why this might be?</p>