第一个合并是用vector集合中的Enumeration。
第二个是Arraylist实现内部类来提供Enumeration。- public static void hebing()throws IOException
- {
- Vector<FileInputStream>v=new Vector<FileInputStream>();
- for (int x=0;x<=3 ;x++ )
- {
- v.add(new FileInputStream("e:\\tupian\\"+x+".part"));
- }
- //v.add(new FileInputStream("e:\\tupian\\0.part"));
- //v.add(new FileInputStream("e:\\tupian\\1.part"));
- //v.add(new FileInputStream("e:\\tupian\\2.part"));
- //v.add(new FileInputStream("e:\\tupian\\3.part"));
- Enumeration<FileInputStream> en=v.elements();
- SequenceInputStream sis=new SequenceInputStream(en);
- FileOutputStream fos=new FileOutputStream("e:\\tupian\\美女.jpg");
- int num=0;
- while ((sis.read())!=-1)
- {
- fos.write(num);
- }
- fos.close();
- sis.close();
- }
复制代码 第二种- public static void hebing2()throws IOException
- {
- ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
- for (int x=0;x<=3 ;x++ )
- {
- al.add(new FileInputStream("e:\\tupian\\"+x+".part"));
- }
- final Iterator<FileInputStream> it=al.iterator();
- Enumeration<FileInputStream> en=new Enumeration<FileInputStream>()
- {
- public boolean hasMoreElements()
- {
- return it.hasNext();
- }
- public FileInputStream nextElement()
- {
- return it.next();
- }
- };
- SequenceInputStream sis=new SequenceInputStream(en);
- FileOutputStream fos=new FileOutputStream("e:\\tupian\\美女复写.jpg");
- int num=0;
- while ((num=sis.read())!=-1)
- {
- fos.write(num);
- }
- sis.close();
- fos.close();
- }
复制代码 这两个合并出来的图片大小是一样大的,但是第一个合并出来的图片打开什么都没有,什么情况? |
|