3-16作业

来源:3-16 自由编程

慕仙0099783

2019-07-15 00:22:55

package com.FileInput;


import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;


public class Filedemo1 {


public static void main(String[] args) {

try {

FileOutputStream fos=new FileOutputStream("/Users/weiwen/Desktop/one.txt");

int n=0;

System.out.println("不使用缓存流");

long star=System.currentTimeMillis();

while(n<10000) {

fos.write(1);

n++;

}

fos.close();

long end=System.currentTimeMillis();

long date=end-star;

System.out.println(date);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

FileOutputStream f2=new FileOutputStream("/Users/weiwen/Desktop/two.txt");

BufferedOutputStream bos=new BufferedOutputStream(f2);

int n=0;

System.out.println("使用缓存流");

long star=System.currentTimeMillis();

while(n<10000) {

f2.write(1);

n++;

}

f2.close();

bos.flush();

long end=System.currentTimeMillis();

long date=end-star;

System.out.println(date);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}


}


写回答

1回答

吃吃吃鱼的猫

2019-07-15

同学你好,程序正确且符合要求。

继续加油吧,祝:学习愉快~

0

0 学习 · 11489 问题

查看课程