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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 盛亚昆 中级黑马   /  2012-3-25 23:31  /  1428 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class SplitFile
{
        public static void main(String[] args) throws IOException
        {
       
                splitFile();
        }
        public static void merge()throws IOException
        {
       
                ArrayList<FileInputStream>al=new ArrayList<FileInputStream>();

                for(int x=1;x<=3;x++)
                {
               
                        al.add(new FileInputStream("C:\\plitfiles\\"+x+".part"))
                }
               
                Iterator<FileInputStream>it=al.iterartor();

                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\\5.bmp");

                byte[]buf=new byte[1024];
                int len=0;
                while((len=sis.read(buf))!=-1)
                {
                        fos.write(buf,0,len);
               
                }
                fos.close();
                sis.close();
       
        }



        public static void splitFile() throws IOException
        {
        FileInputStream fis=new FileInputStream("c:\\1.bmp");

        FileOutputStream fos=null;

        byte[]buf=new byte[1024*1024];

        int len =0;
        int count=1;

        while ((len=fis.read(buf))!=-1)
        {
                fos=new FileOutputStream("c:\\splitfiles\\"+(count++)+".part");
                fos.write(buf,0,len);
                fos.close();//创建一个 赶紧关,
        }
       
        fis.close();
       
       
        }

}
当我要切割1g的视频时怎么办那,1024*1024*1000内存就溢出了,高手指点

2 个回复

倒序浏览
多切割几次啊   切割的次数又没有限制的   
回复 使用道具 举报
每次切割的大小为 64M以内  10多次就好了。 放心的搞吧
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马