本帖最后由 杨兴庭 于 2013-7-23 17:43 编辑
- public static void merge() throws IOException{
- ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
- for(int x=1;x<=3;x++)
- al.add(new FileInputStream("F:\\"+x+".jpg"));
- final Iterator<FileInputStream> it=al.iterator();
- Enumeration<FileInputStream> en=new Enumeration<FileInputStream>(){
- @Override
- public boolean hasMoreElements() {
- // TODO Auto-generated method stub
- return it.hasNext();
- }
- @Override
- public FileInputStream nextElement() {
- // TODO Auto-generated method stub
- return it.next();
- }
- };
- SequenceInputStream sis=new SequenceInputStream(en);
- FileOutputStream fos=new FileOutputStream("F:\\2.jpg");
- byte[] buf=new byte[1024];
- int len=0;
- while((len=sis.read())!=-1)
- fos.write(buf,0,len);
- fos.close();
- sis.close();
- }
复制代码 中间Enumeration的匿名内部类,什么时候去把集合中的数据加入进去了?而且也没有循环 |