FileInputStream fis1 = new FileInputStream("a.txt"); //创建输入流对象,关联a.txt
FileInputStream fis2 = new FileInputStream("b.txt"); //创建输入流对象,关联b.txt
FileInputStream fis3 = new FileInputStream("c.txt"); //创建输入流对象,关联c.txt
Vector<InputStream> v = new Vector<>(); //创建vector集合对象
v.add(fis1); //将流对象添加
v.add(fis2);
v.add(fis3);
Enumeration<InputStream> en = v.elements(); //获取枚举引用
SequenceInputStream sis = new SequenceInputStream(en); //传递给SequenceInputStream构造
FileOutputStream fos = new FileOutputStream("d.txt");
int b;
while((b = sis.read()) != -1) {
fos.write(b);
}
sis.close();
fos.close(); |
|