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();
        }
  • 相关阅读:
    select poll使用
    linux下tomcat shutdown后 java进程依然存在
    poj 1222 EXTENDED LIGHTS OUT(高斯消元)
    poj 2377 Bad Cowtractors
    C#:总结页面传值几种方法
    从 Racket 入门函数式编程
    程序猿接私活经验总结,来自csdn论坛语录
    什么是SEO?SEO干嘛的?怎么做SEO?
    Java设计模式-观察者模式
    非常特别的一个动态规划新手教程
  • 原文地址:https://www.cnblogs.com/zhuyapeng/p/13819710.html
Copyright © 2011-2022 走看看