废话不多说,附上代码:
package com.jiuyi.util;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.List;public class Mp3PaserUtils {private Mp3PaserUtils(){}public static void main(String[] args) {List<String> files = new ArrayList<>(3);files.add("C:/Users/hankui/Desktop/1641348652706.mp3");files.add("C:/Users/hankui/Desktop/1641348681152.mp3");try {combine("C:/Users/hankui/Desktop/11111.mp3",files);} catch (Exception e) {e.printStackTrace();}}public static boolean combine(String outFile, List<String> inFiles) throws Exception{File[] files = new File[inFiles.size()];for (int i = 0; i < files.length; i++){files[i] = new File(inFiles.get(i));}FileInputStream fis = null;FileOutputStream fos = new FileOutputStream(outFile, true); // 合并其实就是文件的续写,写成truefor (int i = 0; i < files.length; i++){fis = new FileInputStream(files[i]);int len = 0;for (byte[] buf = new byte[1024 * 1024]; (len = fis.read(buf)) != -1;){fos.write(buf, 0, len);}}fis.close();fos.close();return true;}}