import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.Enumeration;
import java.util.Vector;
public class 多个文件合并成一个 {
public static void main(String[] args) throws IOException {
long i = System.nanoTime();
System.out.println("正在合并");
FileInputStream f1=new FileInputStream("1.mp3");
FileInputStream f2=new FileInputStream("2.mp3");
FileInputStream f3=new FileInputStream("3.mp3");
Vector<FileInputStream> v=new Vector<>();
v.add(f1);
v.add(f2);
v.add(f3);
Enumeration<FileInputStream> en = v.elements();
SequenceInputStream s=new SequenceInputStream(en);
BufferedInputStream bis=new BufferedInputStream(s);
FileOutputStream f=new FileOutputStream("12合并.mp3");
BufferedOutputStream bos=new BufferedOutputStream(f);
int a;
while((a=bis.read())!=-1){
bos.write(a);
}
bis.close();
bos.close();
long ii = System.nanoTime();
System.out.println("合并完成: "+(ii-i));
}
}
|
|