黑马程序员技术交流社区
标题:
又是一个看视频遇到的问题。在IO流看的应该是关于集合的...
[打印本页]
作者:
yjsf216
时间:
2015-3-9 15:34
标题:
又是一个看视频遇到的问题。在IO流看的应该是关于集合的...
本帖最后由 yjsf216 于 2015-3-9 15:41 编辑
看视频中将三个文件流合并用的是
public static void SequenStreamDemo() throws IOException{
Vector<FileInputStream> v= new Vector<FileInputStream>();
v.add(new FileInputStream("1.txt"));
v.add(new FileInputStream("2.txt"));
v.add(new FileInputStream("3.txt"));
Enumertation<FileInputStream> en= v.elements();
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.wrte(buf, 0, len);
}
fos.close();
sis.close();
}
复制代码
合并成了“4.txt”文件,但是再讲分割流中,毕老师有将三个图片合并
public static void merge() throw IOException{
ArrayList<FileInputStream> al= new ArrayList<FileInputStream>();
for(int x=1; x<=3; x++){
al.add(new FileInputStream(x+".part"));
}
final Iterator<FileInputStream> it= al.iterator();
Enumeration<FileInputStream> en= new Enumeration<FileInputStram>(){
public boolean hasMoreElements(){
return it.hasNext();
}
public FileInputStream nextElement(){
return it.next();
}
};
SequenceInputStream sis= new SequenceInputStream(en);
FileOutputStream fos= new FileOutputStream("0.bmp");
byte[] buf= new byte[1024];
int len=0;
while((len=sis.read(buf)!=-1){
fos.write(buf, 0, len);
}
sis.close();
fos.close();
}
复制代码
那这时候为什么要写了Enumeration集合呢?
作者:
班凤飞
时间:
2015-3-9 18:23
SequenceInputStream这个类构造函数出传入的参数是Enumeration类型的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2