3-16自由编程,作业检查,麻烦看一下

来源:3-16 自由编程

慕的地2082093

2019-10-24 17:11:24

package it.immoc.com;


import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;


public class WeatherTest {

public static void main(String[] args) {

// Weather wt=new Weather();

// new Thread(new GenerateWeather(wt)).start();

// new Thread(new ReadWeather(wt)).start();

try {

FileOutputStream fos=new FileOutputStream("one.txt");

FileOutputStream fos2=new FileOutputStream("two.txt");

BufferedOutputStream bos=new BufferedOutputStream(fos2);

long start1=System.currentTimeMillis();

for(int i=0;i<100000;i++){

fos.write('a');

}

long end1=System.currentTimeMillis();

fos.close();

long start2=System.currentTimeMillis();

for(int i=0;i<100000;i++){

bos.write('a');

}

bos.flush();

long end2=System.currentTimeMillis();

System.out.println("one.txt不使用缓冲流来写");

System.out.println("用时为:"+(end1-start1));

System.out.println("two.txt使用缓冲流来写");

System.out.println("用时为:"+(end2-start2));

System.out.println("节省时间:"+((end1-start1)-(end2-start2)));

bos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}


写回答

1回答

好帮手慕酷酷

2019-10-24

同学你好,代码完成的很好,逻辑清晰~

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 11489 问题

查看课程