public class SequenceInputStreamTest {
public static void main(String[] args) {
Vector<FileInputStream> v = new Vector<>();
SequenceInputStream sis = null;
FileOutputStream fos = null;
try {
v.add(new FileInputStream("e:\\copyfile\\1.txt"));
v.add(new FileInputStream("e:\\copyfile\\2.txt"));
v.add(new FileInputStream("e:\\copyfile\\3.txt"));
Enumeration<FileInputStream> en = v.elements();
sis = new SequenceInputStream(en);
fos = new FileOutputStream("e:\\copyfile\\4.txt");
byte[] buf = new byte[1024];
int len = 0;
while((len = sis.read(buf)) != -1){
fos.write(buf,0,len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fos == null)
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
if(sis == null)
try {
sis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} |
|