字节流高效缓冲区文件复制

Posted 静赋清承

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字节流高效缓冲区文件复制相关的知识,希望对你有一定的参考价值。

    public static void fileCopy2BufferByte(String oldFileName,String newFileName){
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try{
            bis = new BufferedInputStream(new FileInputStream(oldFileName));
            bos = new BufferedOutputStream(new FileOutputStream(newFileName));
            byte[] bytes = new byte[1024];
            int len = -1;
            while ((len = bis.read(bytes))!=-1)bos.write(bytes,0,len);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(bis!=null)bis.close();
                if(bos!=null)bos.close();
            }catch (IOException ee){
                ee.printStackTrace();
            }
        }
    }

 

以上是关于字节流高效缓冲区文件复制的主要内容,如果未能解决你的问题,请参考以下文章

Java复制二进制文件

IO流 - 复制文件(字节缓冲流+字节流)

IO流,字节流复制文件,字符流+缓冲复制文件

字节流复制文件和字节缓冲流复制文件的时间比较

文件的复制方式

简单利用缓冲字节流复制图片