I do not know why my java program runs out of memeory about half way through the list?
public static void getMovieFile() { int myBuffer, counter = 0; String aFile = "movies.list"; Pattern myIgnore = Pattern.compile("\".*"); Pattern myYear = Pattern.compile("\\(\\d\\d\\d\\d.*"); String title, year; Scanner myScanner; try { //New Scanner stream for the file input (aFile) myScanner = new Scanner(new FileInputStream(aFile), "ISO-8859-1"); //Skip first 20 lines (Movies are at line 1,312,533) while(counter<20){ myScanner.nextLine(); counter++; } //Reset counter counter = 0; //While Scanner starts with quotation marks (") skip line while (myScanner.hasNext(myIgnore)){ myScanner.nextLine(); } //While Scanner has next token read token while (myScanner.hasNext()) { //Declaring and instantiating title (Blank) title = ""; //While Scanner is not movie year concat title with next token while(!myScanner.hasNext(myYear)){ title = title.concat(myScanner.next()).concat(" "); } //Else return and substring movie year year = myScanner.next().toString().substring(1,5); //Inputting title and year into the object database //While year is not empty while(!(year.isEmpty()&&title.isEmpty())){ try{ //Check if year is a valid integer myBuffer = Integer.parseInt(year); //Input records into array MovieMenu.movies.inputMovie(title, myBuffer, "NA", "NA", 0.0, "NA", "NA", counter); //Reset title and year for new input System.out.println("Inputting Movie: " +title +"Year:" +year +"Position: " +counter); title = year = ""; } catch(NumberFormatException e) { //Parse Integer Number format exception Logger.getLogger(MovieListImport.class.getName()).log(Level.SEVERE, null, e); System.out.println("Error: Invalid release"); } //Increase position in movies array list counter++; } //Move Scanner to next line myScanner.nextLine(); } //Close myScanner myScanner.close(); } catch (FileNotFoundException ex) { //FileInputStream File not found exception Logger.getLogger(MovieListImport.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Error: File not Found"); } catch (SecurityException e){ //FileInputStream Security exception Logger.getLogger(MovieListImport.class.getName()).log(Level.SEVERE, null, e); System.out.println("Error: Cannot read file"); } catch (NullPointerException ioe){ //Scanner Null pointer exception Logger.getLogger(MovieListImport.class.getName()).log(Level.SEVERE, null, ioe); System.out.println("Error: Corrupt file"); } catch (NoSuchElementException e){ //Scanner No such element exception Logger.getLogger(MovieListImport.class.getName()).log(Level.SEVERE, null, e); System.out.println("Error: End of file"); } }