StackOverflowError while performing external sort
<p>I am trying to do external merge sort. Method: opening all the files in the folder 'output' and getting 1st line and sorting it, and writing it in the 'final' file and then getting the 2nd line of that file and repeating. I get an StackOverflowError. Here my file size is greater then memory.</p>

<pre><code> public class mergefile6 {
    public static ArrayList&lt;String&gt; al = new ArrayList&lt;String&gt;();
    static HashMap hm = new HashMap();
    public static String line;
    public static String[][] filepoint = new String[100][2];
    public static int fileline=1;  
    public static int i=0;  

    public static void main(String[] args) throws Exception{
        fileread();
    }
    public static void fileread() throws Exception{     
        FileReader fileReader = null;
        BufferedReader bufferedReader = null;       
    try {
                File folder = new File("./output/");        
                if (folder.isDirectory()) {
                    for (File file : folder.listFiles()) {
                            fileReader = new FileReader(file);
                            bufferedReader = new BufferedReader(fileReader);        
                            int lineCount = 0;
                        while ((line = bufferedReader.readLine())!=null) {
                                lineCount++;
                                if (1 == lineCount) {
                                    hm.put(line,file);
                                    al.add(line);
                                    filepoint[i][0]=file.toString();
                                filepoint[i][1]=Integer.toString(fileline);
                                    ++i;
                                }                                               
                            }               
                    }
                }
                if (null != fileReader){
                    try {
                            fileReader.close();
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
        }
        if (null != bufferedReader){
                    try {
                            bufferedReader.close();
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
        }
        Sorting(al);
        test(al);
    } catch (Exception e) {
    } finally { 
    }
  }
  public static void Sorting(ArrayList&lt;String&gt; al)throws Exception{
    int length = al.size();
    ArrayList&lt;String&gt; tmp = new ArrayList&lt;String&gt;(al);
    mergeSort(al, tmp,  0,  al.size() - 1);
  }
  private static void mergeSort(ArrayList&lt;String&gt; al, ArrayList&lt;String&gt; tmp, int left, int right){
    //sort code
  } 

public static void test(ArrayList&lt;String&gt; al) throws Exception{
    BufferedWriter bw = null;
    FileWriter fw = null;
        fw = new FileWriter("final",true);
        bw = new BufferedWriter(fw);
        bw.write(al.get(0)+" \n");
        //bw.flush();
        bw.close();
        fw.close();
        String filename = hm.get(al.get(0)).toString();
        hm.remove(al.get(0));
        al.remove(0);
        fileforward(filename,al);
}
public static void fileforward(String filename,ArrayList&lt;String&gt; al) throws Exception{
    long list;
    FileReader fr = null;
    BufferedReader br = null;
    fr = new FileReader(filename);
    br = new BufferedReader(fr);
    for(int j=0;j&lt;i;++j){
        if(filepoint[j][0] == filename){
            fileline = Integer.parseInt(filepoint[j][1]); 
            list = br.skip(99*fileline);
            if((line = br.readLine())!=null){
                hm.put(line,filename);
                al.add(line);
                ++fileline;
                filepoint[j][1]=Integer.toString(fileline);
                br.close(); fr.close();
            }else{}             
        }
    }
    if(al.size()==3){
    Sorting(al);
    test(al);       }                               
}   
 }
</code></pre>

<blockquote>
  <p>What may be causing this error to come?</p>
</blockquote>