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 }
  • 相关阅读:
    Linux命令行界面使用代理上网
    .NET 开发框架 代码生成器
    如何正确地学习
    Ubuntu实用命令——不断更新中......
    MSSQL如何快速清除数据库日志转,经实践有效
    C# 获取机器码
    C#中得到每周,每月,每季,每年的年初末日期
    asp.net(C#)解析Json的类代码
    由拖库攻击谈口令字段的加密策略(数据库加密)
    用sql查询当天,一周,一个月的数据
  • 原文地址:https://www.cnblogs.com/SubFirst-D/p/7058840.html
Copyright © 2011-2022 走看看