public static void mergeFiles(final File file1,final File file2,final File outputFile){
  if (!isReadable(file1) || !isReadable(file2) || !outputFile.exists() && !makeDirsForFile(outputFile)) {
    return;
  }
  try {
    FileInputStream fis1=new FileInputStream(file1);
    FileInputStream fis2=new FileInputStream(file2);
    SequenceInputStream sis=new SequenceInputStream(fis1,fis2);
    FileOutputStream fos=new FileOutputStream(outputFile);
    int count;
    byte[] temp=new byte[4096];
    while ((count=sis.read(temp)) != -1) {
      fos.write(temp,0,count);
    }
    FileUtils.sync(fos);
    fos.close();
    sis.close();
    fis1.close();
    fis2.close();
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}

public static void mergeFiles ( final File file1 , final File file2 , final File outputFile ) { if ( ! isReadable ( file1 ) || ! isReadable ( file2 ) || ! outputFile . exists ( ) && ! makeDirsForFile ( outputFile ) ) { return ; } try { FileInputStream fis1 = new FileInputStream ( file1 ) ; FileInputStream fis2 = new FileInputStream ( file2 ) ; SequenceInputStream sis = new SequenceInputStream ( fis1 , fis2 ) ; FileOutputStream fos = new FileOutputStream ( outputFile ) ; int count ; byte [ ] temp = new byte [ 4096 ] ; while ( ( count = sis . read ( temp ) ) != - 1 ) { fos . write ( temp , 0 , count ) ; } FileUtils . sync ( fos ) ; fos . close ( ) ; sis . close ( ) ; fis1 . close ( ) ; fis2 . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
merge two files into a new file
