哪里有问题

哪里有问题

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();
        }
    }
 
}

运行结果很不正常

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
慕姐5088615 2017-11-03 09:52:19

System.out.println("two不使用缓冲流来写\n用时:" + (c - d));

改成System.out.println("two不使用缓冲流来写\n用时:" + (d - c));

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师