麻烦老师帮忙批改下,谢谢

来源:3-16 自由编程

ByteDancer07

2020-01-14 13:26:38

package com.kai.file;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedPractice {

	public static void main(String[] args) { 
		//用FileInputStream写入
		try {
			FileOutputStream one = new FileOutputStream("one.txt");
			long startTime1 = System.currentTimeMillis();
			for(int i=0;i<10000;i++) {
				one.write((char)i);
			}
			long endTime1 = System.currentTimeMillis();
			long oneTime = endTime1-startTime1;
			System.out.println("one.txt不使用缓冲流来写\n用时为:");
			System.out.print(oneTime);
			one.close();
			
			System.out.println();
			//用BufferedOutputScream写入
			BufferedOutputStream two = new BufferedOutputStream(new FileOutputStream("two.txt"));
			long startTime2 = System.currentTimeMillis();
			for(int i=0;i<10000;i++) {
				two.write((char)i);
			}
			long endTime2 = System.currentTimeMillis();
			System.out.println("two.txt用缓冲流来写\n用时为:");
			long twoTime = endTime2-startTime2;
			System.out.println(twoTime);
			two.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}
		

	}

}


写回答

1回答

好帮手慕小脸

2020-01-14

同学你好,代码编写的不错,继续加油!

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

0

0 学习 · 11489 问题

查看课程