public static void mothed_2() {
ArrayList<FileInputStream> list = new ArrayList<>();
SequenceInputStream sis = null;
FileOutputStream fos = null;
try {
list.add(new FileInputStream("e:\\copyfile\\1.txt"));
list.add(new FileInputStream("e:\\copyfile\\2.txt"));
list.add(new FileInputStream("e:\\copyfile\\3.txt"));
Enumeration<FileInputStream> em = Collections.enumeration(list);
sis = new SequenceInputStream(em);
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();
}
}
} |
|