合并分割后的文件

    public static void main(String[] args) throws IOException {
        
        File dir=new File("c:\\artfiles");
        mergeFile(dir);
    }
    public static void mergeFile(File dir) throws IOException
    {
        ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
        
        for(int x=1;x<=5;x++){
            al.add(new FileInputStream(new File(dir,x+".part")));
        }
        Enumeration<FileInputStream> en=Collections.enumeration(al);
        SequenceInputStream sis= new SequenceInputStream(en);
        
        FileOutputStream fos=new FileOutputStream(new File(dir,"mp3.mp3"));
        byte[] buf=new byte[1024];
        int len=0;
        while((len=sis.read(buf))!=-1)
        {
            fos.write(buf,0,len);
        }
        fos.close();
        sis.close();
    }

posted on 2012-10-22 13:36  蝌蚪的精神  阅读(124)  评论(0编辑  收藏  举报

导航