哪里有问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class Buffered_Stream { public static void main(String[] args) { try { FileOutputStream fos1 = new FileOutputStream("one.txt", true); FileOutputStream fos2 = new FileOutputStream("two.txt", true); BufferedOutputStream bos = new BufferedOutputStream(fos2); long a = System.currentTimeMillis(); for (int i = 1; i <= 100000; i++) { fos1.write('a'); } fos1.close(); long b = System.currentTimeMillis(); System.out.println("one不使用缓冲流来写\n用时:" + (b - a)); long c = System.currentTimeMillis(); for (int i = 1; i <= 100000; i++) { bos.write('a'); bos.flush(); } fos2.close(); bos.close(); long d = System.currentTimeMillis(); System.out.println("two不使用缓冲流来写\n用时:" + (c - d)); System.out.println("用缓冲流来写节省了" + ((b - a) - (c - d))); System.out.println(b - a); } catch (FileNotFoundException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }} |
运行结果很不正常
67
收起
正在回答 回答被采纳积分+1
1回答
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星