1 private static boolean combine(String outFile, List<String> inFiles) throws Exception{ 2 File[] files = new File[inFiles.size()]; 3 for(int i = 0; i < files.length; i++){ 4 files[i] = new File(inFiles.get(i)); 5 } 6 FileInputStream fis = null; 7 FileOutputStream fos = new FileOutputStream(outFile, true);//合併其實就是文件的續寫,寫成true 8 for (int i = 0; i < files.length; i++){ 9 fis = new FileInputStream(files[i]); 10 int len = 0; 11 for (byte[] buf = new byte[1024 * 1024]; (len = fis.read(buf)) != -1;){ 12 fos.write(buf, 0, len); 13 } 14 fis.close(); 15 } 16 fos.close(); 17 return true; 18 }