- import java.io.*;
- import java.util.*;
- class SequenceDemo {
- public static void main(String[] args) throws IOException{
- Vector<FileInputStream> ve = new Vector<FileInputStream>();
- ve.add(new FileInputStream("1.txt"));
- ve.add(new FileInputStream("2.txt"));
- ve.add(new FileInputStream("3.txt"));
- Enumeration<FileInputStream> en = ve.elements();
- /*合并流是必须接收枚举的,所以用Vector得到了一个枚举,
- 请问这里的枚举,和张孝祥老师将的枚举有什么关系吗?*/
- SequenceInputStream sis = new SequenceInputStream(en);
- FileOutputStream fos = new FileOutputStream("4.txt");
- byte[] buf = new byte[1024];
- int len =0;
- while((len=sis.read(buf))!=-1){
- fos.write(buf,0,len);
- }
- fos.close();
- sis.close();
- }
- }
复制代码 |