原来是这样的
FileInputStream fis1 = new FileInputStream("a.txt");
FileInputStream fis2 = new FileInputStream("b.txt");
FileInputStream fis3 = new FileInputStream("c.txt");
Vector<FileInputStream> v = new Vector<>();
v.add(fis1);
v.add(fis2);
v.add(fis3);
Enumeration<FileInputStream> en= v.elements();
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fos = new FileOutputStream("d.txt");
int n;
while((n = sis.read()) != -1){
fos.write(n);
}
sis.close();
fos.close();
}
我自己把他改成了这样
Vector<FileInputStream> v = new Vector<>();
v.add(new FileInputStream("a.txt"));
v.add(new FileInputStream("b.txt"));
v.add(new FileInputStream("c.txt"));
SequenceInputStream sis = new SequenceInputStream(v.elements());
FileOutputStream fos = new FileOutputStream("d.txt");
int n;
while((n = sis.read()) != -1){
fos.write(n);
}
sis.close();
fos.close();
}
运行出来是对的,但是不知道这样对不对,求大神指点 |
|