package merge;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
public class Merge {
public static void main(String[] args) throws Exception {
String directory = "C:\\Users\\Administrator\\Desktop\\zz";
File path = new File(directory);
File[] files = path.listFiles();
ArrayList<byte[]> list = new ArrayList<>();
FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\yy\\test.pdf", true);
BufferedOutputStream outputStream = new BufferedOutputStream(fileOutputStream);
for (int i = 0; i < files.length; i++) {
String st = directory+"\\"+"test.part"+i;
Path pt = Paths.get(st);
byte[] bt = Files.readAllBytes(pt);
list.add(bt);
}
System.out.println();
for (int i = 0; i <list.size() ; i++) {
outputStream.write(list.get(i));
}
}
}
标签:文件,file,java,io,合并,File,new,import
From: https://www.cnblogs.com/used-conduit-onion/p/18537602