zoukankan      html  css  js  c++  java
  • 文件写入时使用缓冲区与不使用缓冲区效率提升3倍测试

    //不使用缓冲区,用时100MS
        public static void main(String[] args) {
            Writer writer = null;
            try {
                Long startTime = System.currentTimeMillis();
                writer = new FileWriter("D:\zp_project\rt.txt");
                for (int i = 0; i <500000 ; i++) {
                    writer.write(i);
                }
                Long endTime = System.currentTimeMillis();
                System.out.println(endTime-startTime);
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
    
    //使用缓冲区 用时33MS
        public static void main(String[] args) {
            Writer writer = null;
            BufferedWriter bufferedWriter = null;
    
            try {
                Long start = System.currentTimeMillis();
                writer = new FileWriter("D:\zp_project\bf.txt");
                bufferedWriter = new BufferedWriter(writer);
                for (int i = 0; i <500000 ; i++) {
                    bufferedWriter.write(i);
                }
                Long end = System.currentTimeMillis();
                System.out.println(end - start);
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    bufferedWriter.close();
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    
        }
  • 相关阅读:
    eclipse部署
    jsp—eclipse配置
    虚拟路径和虚拟主机
    tomcat配置
    初来乍到K
    【转】https://和http://区别
    【转】编码格式
    【转】如何使用瑞萨E10A调试SH系列不带片内FLASH的单片机
    【转】UML
    软考_系统架构师
  • 原文地址:https://www.cnblogs.com/bing2017/p/14342587.html
Copyright © 2011-2022 走看看