本帖最后由 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集合呢? |
|