How can I stop scanning a file once array is full?
<p>I am working on a Java project which has a method that reads a file, converts the file elements to objects, and adds them to an array. A maximum of thirty objects can be added to the array. The file I was assigned has about 100 objects in it. Whenever I try to read the file, I get this error:</p>

<pre><code>java.lang.ArrayIndexOutOfBoundsException: 30
</code></pre>

<p>I know what the error means, but I don't know how to stop scanning the file once the array limit has been reached. </p>

<p>This is what I've tried so far, but it doesn't seem to work:</p>

<pre><code>String skip;

if(count == MAX){
     skip = scanFile.nextLine();
  }
</code></pre>