public static void main(String[] args)throws IOException {
Vector<FileInputStream> vc=new Vector<FileInputStream>();
vc.add(new FileInputStream("D:\\MyEclipse 8.5\\Workspaces\\IOStream\\1.txt"));
vc.add(new FileInputStream("D:\\MyEclipse 8.5\\Workspaces\\IOStream\\2.txt"));
vc.add(new FileInputStream("D:\\MyEclipse 8.5\\Workspaces\\IOStream\\3.txt"));
Enumeration<FileInputStream> en=vc.elements();
SequenceInputStream sis=new SequenceInputStream(en);
FileOutputStream fos=new FileOutputStream("D:\\MyEclipse 8.5\\Workspaces\\IOStream\\4.txt");
byte[] by=new byte[1024];
int len=0;
while((len=sis.read(by))!=-1)
{
fos.write(by,0,len);
}
sis.close();
fos.close();
}
在合并流中,老师演示是用到了Vector容器,为什么要用到Enumeration这个类的引用?
还有那个是不是一定要用vector集合来对多个输入流进行存储?
还有能不能不用Vector 行不行?用List行不?(用其他集合具体要怎么做?)
还有就是上面的是不是合并流的常用写法? |