A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 雨下阳光 中级黑马   /  2014-9-30 22:40  /  851 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.SequenceInputStream;
  8. import java.util.Enumeration;
  9. import java.util.Vector;

  10. public class EnumerationDemo {
  11.         public static void main(String[] args) throws IOException{
  12.                 Vector<FileInputStream> v=new Vector<FileInputStream>();
  13.                 v.add(new FileInputStream("D:\\Media\\1.txt"));
  14.                 v.add(new FileInputStream("D:\\Media\\2.txt"));
  15.                 v.add(new FileInputStream("D:\\Media\\3.txt"));
  16.                 Enumeration<FileInputStream> e=v.elements();
  17.                 SequenceInputStream ss=new SequenceInputStream(e);
  18.                 FileOutputStream fos=new FileOutputStream("D:\\Media\\4.txt");
  19.                 byte[] bt=new byte[1024];
  20.                 int len=0;
  21.                 while((len=ss.read(bt))!=-1)
  22.                                 fos.write(bt,0,len);
  23.                 fos.close();
  24.                 ss.close();
  25.                
  26.         }
复制代码

这里的SequenceInputStream ss=new SequenceInputStream(e);参数一定要是Enumeration枚举型的。既然枚举已经被迭代器取代,为什么不把SequenceInputStream修改修改呢?

评分

参与人数 1技术分 +1 收起 理由
敏敏好学 + 1

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马