A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 午夜b'Boy 中级黑马   /  2014-3-1 22:41  /  749 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

方式一       
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
                for(int x=0; x<partcount; x++){
                        al.add(new FileInputStream(new File(dir,x+SP)));
                }
                Enumeration<FileInputStream> en = Collections.enumeration(al);
                SequenceInputStream sis = new SequenceInputStream(en);
方式二
public static void merge()throws IOException
        {
                ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();

                for(int x=1; x<=3; x++)
                {
                        al.add(new FileInputStream("c:\\splitfiles\\"+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("c:\\splitfiles\\0.bmp");

                byte[] buf = new byte[1024];

                int len = 0;

                while((len=sis.read(buf))!=-1)
                {
                        fos.write(buf,0,len);
                }

                fos.close();
                sis.close();
        }

评分

参与人数 1技术分 +1 收起 理由
何伟超 + 1

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马