title: Java Reading big file java heap space
body: <p>I have written this code:</p>
  
  <pre><code>try(BufferedReader file = new BufferedReader(new FileReader("C:\\Users\\User\\Desktop\\big50m.txt"));){
                String line;
                StringTokenizer st;
  
                while ((line = file.readLine()) != null){
                    st  = new StringTokenizer(line); // Separation of integers of the file line
                    while(st.hasMoreTokens())
                         numbers.add(Integer.parseInt(st.nextToken())); //Converting and adding to the list of numbers
                    }
  
            }
            catch(Exception e){
                System.out.println("Can't read the file...");
  
            }
  </code></pre>
  
  <p>the big50m file has 50.000.000 integers and i get this runtime error:</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:3332)
      at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:596)
      at java.lang.StringBuffer.append(StringBuffer.java:367)
      at java.io.BufferedReader.readLine(BufferedReader.java:370)
      at java.io.BufferedReader.readLine(BufferedReader.java:389)
      at unsortedfilesapp.UnsortedFilesApp.main(UnsortedFilesApp.java:37)
  C:\Users\User\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
  BUILD FAILED (total time: 5 seconds)
  </code></pre>
  
  <p>I think the problem is the string variable named <code>line</code>. Can you tell me how
  to fix it ? Because i want fast reading i use StringTokenizer.</p>