作業麻煩確認一下是否有需要改進
来源:3-16 自由编程
胖達
2019-10-18 08:10:44
package com.imooc.file;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamHome {
public static void main(String[] args) {
// TODO Auto-generated method stub
File fi1 = new File("one.txt");
File fi2 = new File("two.txt");
try {
fi1.createNewFile();
fi2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FileOutputStream fos1 = new FileOutputStream(fi1);
byte[] b = new byte[100000];
long one1 = System.currentTimeMillis();
for(int i = 0 ;i<b.length;i++) {
fos1.write('a');
}
long one2 = System.currentTimeMillis();
System.out.println(one2-one1);
FileOutputStream fos2 = new FileOutputStream(fi2);
BufferedOutputStream bos = new BufferedOutputStream(fos2);
long two1 = System.currentTimeMillis();
for(int i = 0 ;i<b.length;i++) {
bos.write('a');
}
long two2 = System.currentTimeMillis();
System.out.println(two2-two1);
bos.close();
fos2.close();
fos1.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}1回答
好帮手慕酷酷
2019-10-18
同学你好,代码编写的不错,如果输出一些提示信息更好了哦~
如:



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