zoukankan      html  css  js  c++  java
  • I/O字节流

    下面代码对比:一次读取一个字节和一次读取一个数组及应用缓冲流耗时对比

        /*
        * 复制大文件速率对比
        * */
        //耗时:很大,一分钟以上
        public static void copy1() throws IOException {
            String path="E:\Java\00_0\0.avi";
            String path1="E:\Java\00_0\01.avi";
            FileInputStream fis=new FileInputStream(path);
    
            FileOutputStream fos=new FileOutputStream(path1);
    
            int read;
            while ((read=fis.read())!=-1){
                fos.write(read);
            }
    
            fis.close();
            fos.close();
        }
    
        //耗时:556
        public static void copy2() throws IOException {
            String path="E:\Java\00_0\0.avi";
            String path1="E:\Java\00_0\02.avi";
            FileInputStream fis=new FileInputStream(path);
    
            FileOutputStream fos=new FileOutputStream(path1);
    
            byte[] arr=new byte[1024];
            int len;
            while ((len=fis.read(arr))!=-1){
                fos.write(arr,0,len);
            }
    
            fis.close();
            fos.close();
        }
    
    
        //耗时:2541
        public static void copy3() throws IOException {
            String path="E:\Java\00_0\0.avi";
            String path1="E:\Java\00_0\03.avi";
            BufferedInputStream fis=new BufferedInputStream(new FileInputStream(path));
    
            BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(path1));
    
            int read;
            while ((read=fis.read())!=-1){
                fos.write(read);
            }
    
            fis.close();
            fos.close();
        }
    
        //耗时:171
        public static void copy4() throws IOException {
            String path="E:\Java\00_0\0.avi";
            String path1="E:\Java\00_0\04.avi";
            BufferedInputStream fis=new BufferedInputStream(new FileInputStream(path));
    
            BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(path1));
    
            byte[] arr=new byte[1024];
            int len;
            while ((len=fis.read(arr))!=-1){
                fos.write(arr,0,len);
            }
    
            fis.close();
            fos.close();
        }
  • 相关阅读:
    MongoDB compass 连接不上远程服务器的解决方法
    art-template 模版引擎
    mongodb数据库的集合关联
    捕获mongoogse 错误信息
    inux下使用自带mail发送邮件告警
    rinted端口转发工具
    windows安装PHP IIS MYSQL
    sql语句查询知识点
    maven加速镜像
    docker启动容器关于防火墙报错
  • 原文地址:https://www.cnblogs.com/zhuyapeng/p/13819710.html
Copyright © 2011-2022 走看看