- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.SequenceInputStream;
- import java.util.Enumeration;
- import java.util.Vector;
- public class EnumerationDemo {
- public static void main(String[] args) throws IOException{
- Vector<FileInputStream> v=new Vector<FileInputStream>();
- v.add(new FileInputStream("D:\\Media\\1.txt"));
- v.add(new FileInputStream("D:\\Media\\2.txt"));
- v.add(new FileInputStream("D:\\Media\\3.txt"));
- Enumeration<FileInputStream> e=v.elements();
- SequenceInputStream ss=new SequenceInputStream(e);
- FileOutputStream fos=new FileOutputStream("D:\\Media\\4.txt");
- byte[] bt=new byte[1024];
- int len=0;
- while((len=ss.read(bt))!=-1)
- fos.write(bt,0,len);
- fos.close();
- ss.close();
-
- }
复制代码
这里的SequenceInputStream ss=new SequenceInputStream(e);参数一定要是Enumeration枚举型的。既然枚举已经被迭代器取代,为什么不把SequenceInputStream修改修改呢? |