zoukankan      html  css  js  c++  java
  • (I/O流)在100ms内桌面上生成一个200M大小的文件

    最终速度取决于硬盘的读写速度

     1 package com.laurdawn;
     2 
     3 import java.io.File;
     4 import java.io.FileInputStream;
     5 import java.io.FileOutputStream;
     6 import java.io.IOException;
     7 
     8 public class test {
     9 
    10     public static void main(String[] args) {
    11         // TODO Auto-generated method stub
    12         File f1 = new File("C:/Users/Administrator/Desktop/test.txt");
    13         try {
    14             FileOutputStream fos = new FileOutputStream(f1);
    15             if (!f1.exists()) {
    16                 try {
    17                     f1.createNewFile();
    18                 } catch (IOException e) {
    19                     // TODO Auto-generated catch block
    20                     e.printStackTrace();
    21                 }
    22             }
    23             byte[] buffer = new byte[1024 * 200];
    24             long start = System.currentTimeMillis();
    25             for (int i = 0; i < 1024; i++) {
    26                 fos.write(buffer);
    27                 fos.flush();
    28 
    29             }
    30             long end = System.currentTimeMillis();
    31             long time = end - start;
    32             System.out.println("写入时间:" + time + "ms");
    33             fos.close();
    34         } catch (IOException e1) {
    35             // TODO Auto-generated catch block
    36             e1.printStackTrace();
    37         }
    38     }
    39 
    40 }
  • 相关阅读:
    4.C#的选择语句练习
    3.C#中的选择语句
    java包静态导入,继承
    新的学期要继续学习喽
    桌球小游戏
    JAVA和C语言的区别
    BIV+CSS网页的标准化布局
    层叠样式表
    学PHP也要懂得HTML
    web开发入门
  • 原文地址:https://www.cnblogs.com/laurdawn/p/5631913.html
Copyright © 2011-2022 走看看