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

 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 }

 

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2021-10-10
  • 2021-05-09
  • 2021-04-16
  • 2022-01-14
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案