title: Java use 1 billion digits of pi
body: <p>I am trying to make a program that will search the first 1 billion digits of pi and will find a user specified number, the problem I am facing is how to use pi...  I have a .txt file that contains pi (I also broke it to 96 different files because java couldn't handle such a big file) all the digits are in the first line....
  Code (only to read and save pi using the 96 files):</p>
  
  <pre><code>for(int i = 1;i &lt;= 96; i++){
          String filename = "";
          if(i &lt;= 9){
              filename = "res//t//output2_00000" + i + "(500001).txt";
          }else{
              filename = "res//t//output2_0000" + i + "(500001).txt";
          }
          Scanner inFile = new Scanner(new FileReader(filename));
          ar.add(inFile.nextLine());
      }
      List&lt;String&gt; pi = new ArrayList&lt;String&gt;();
      for(int i = 0; i&lt;97;i++){
          System.out.println(i);
          for(String j : ar.get(i).split("")){
              pi.add(j);
          }
      }
  </code></pre>
  
  <p>This seems to work fine up to a point where it crashes with the following error (the last print statement is 3):</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  at java.lang.String.substring(Unknown Source)
  at java.lang.String.subSequence(Unknown Source)
  at java.util.regex.Pattern.split(Unknown Source)
  at java.lang.String.split(Unknown Source)
  at java.lang.String.split(Unknown Source)
  at main.Main.main(Main.java:29)
  </code></pre>
  
  <p>Is there a way to overcome that, and is there a way to make it go faster?
  Thanks in advance.</p>