• 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();
        }
  • 相关阅读:
    [zz]libvirt中CPU和内存的细粒度管理机制
    SAP 模块中文解释
    邪恶的Php一句话木马 assert函数制作简单木马
    PHP开发中三维数组的应用
    返回本机时间或服务器时间
    向SQL中插入数据
    Word的字体
    人生如锅
    打开指定的文件
    计算最大序号
  • 原文地址:https://www.cnblogs.com/zhuyapeng/p/13819710.html
Copyright © 2020-2023  润新知