zoukankan      html  css  js  c++  java
  • IO中关于自定义缓冲区和使用默认缓冲区哪个效率更高的对比

    //自己测试了一个3.8G的文件,有兴趣的可以自己试试看,初学java写的不对的地方希望大家能指出,有疑问可以留言一起探讨,谢谢!
     1 package cn.String.Day.IO;
     2 
     3 import java.io.*;
     4 
     5 /**
     6  * Created by Void on 2017/6/20.
     7  */
     8         public class copyInputOutput {
     9             public static void main(String[] args) throws IOException {
    10                 bufferTime();
    11                 imbufferTime();
    12 
    13             }
    14     private static void imbufferTime() throws IOException {
    15         FileInputStream fileInputStream = new FileInputStream("D:\360安全浏览器下载\win7中文旗舰版64位系统.iso");
    16         FileOutputStream fileOutputStream = new FileOutputStream("e:\win7旗舰版64bit.iso");
    17         long startTime = System.currentTimeMillis() ;
    18         byte[] by = new byte[4096];
    19         int len = 0;
    20         while ((len = fileInputStream.read(by))!=-1){
    21             fileOutputStream.write(by,0,len);
    22 
    23         }
    24         fileOutputStream.close();
    25         fileInputStream.close();
    26         long endTime = System.currentTimeMillis();
    27         System.out.println("自定义缓冲花费的时间是:"+(endTime-startTime)/1000);
    28     }
    29 
    30     private static void bufferTime() throws IOException {
    31 
    32         BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("D:\360安全浏览器下载\win7中文旗舰版64位系统.iso"),4096);
    33 
    34         BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("e:\win7旗舰版64bit.iso"),4096);
    35         long startTime = System.currentTimeMillis() ;
    36         int len = 0;
    37         while ((len = bufferedInputStream.read())!=-1){
    38             bufferedOutputStream.write(len);
    39 
    40         }
    41         bufferedOutputStream.close();
    42         bufferedInputStream.close();
    43         long endTime = System.currentTimeMillis();
    44         System.out.println("原缓冲花费的时间是:"+(endTime-startTime)/1000);
    45     }
    46 }
  • 相关阅读:
    MySQL系列
    Python小白之路
    nrm安装使用(mac)
    npm 发布一个包(已有自己私服的情况)
    vuex简单使用
    在vue中使用ztree树插件
    题库1
    设计模式读书笔记
    ORM框架学习之EF
    net+Oracle开发过程中遇到的小问题
  • 原文地址:https://www.cnblogs.com/SubFirst-D/p/7058840.html
Copyright © 2011-2022 走看看