java - How can I stop scanning a file once array is full? -


i working on java project has method reads file, converts file elements objects, , adds them array. maximum of thirty objects can added array. file assigned has 100 objects in it. whenever try read file, error:

java.lang.arrayindexoutofboundsexception: 30 

i know error means, don't know how stop scanning file once array limit has been reached.

this i've tried far, doesn't seem work:

string skip;  if(count == max){      skip = scanfile.nextline();   } 

it better close scanner once have input max:

 final int max = 30;  int count = 0;   while(count <= max){      string line = scanner.nextline();      //process line , add array      myarray[count++] = //whatever  }  //close scanner  scanner.close(); 

also remember arrays 0 based index.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -