title: Merging multiple files in java
body: <p>I have an array of files that i want to merge. This is what I tried but it did not work.</p>
  
  <pre><code> public static void joinf(File f1, File f2){
  
      try{
  
          InputStream in = new FileInputStream(f1);
  
  
          OutputStream out = new FileOutputStream(f2,true);
  
          byte[] buf = new byte[8192];
          int len;
          while ((len = in.read(buf)) &gt; 0){
              out.write(buf, 0, len);
          }
          in.close();
          out.close();
          System.out.println("File copied.");
      }
      catch(FileNotFoundException ex){
          System.out.println(ex.getMessage() + " in the specified directory.");
          System.exit(0);
      }
      catch(IOException e){
          System.out.println(e.getMessage());            
      }
  }
  
  
  public void pro(File a,File[]b){
      for(int i=0;i&lt;b.length;i++){
  
  
          joinf(a,b[i]);
      }
  }
  </code></pre>