FileInputStream fis = new FileInputStream("IO\\海尔恰饭.mp3");
FileOutputStream fos = new FileOutputStream("IO\\a1.mp3");
long s = System.currentTimeMillis();
byte[] bytes = new byte[1];
int len = 0;
while ((len = fis.read(bytes)) != -1){
fos.write(bytes);
}
long e = System.currentTimeMillis();
System.out.println("程序耗时:" + (e-s) + "秒");程序耗时:23954秒
byte[] bytes = new byte[1];
逐一复制速度很慢
.
.
进行优化利用内存缓存区
byte[] bytes = new byte[1024];程序耗时:41秒
.
.
.
.
BufferedWriter 字符写入
long s = System.currentTimeMillis();
BufferedWriter bos = new BufferedWriter(new FileWriter("IO\\a.txt"));
for(int i =0;i <10;i++){
bos.write("爱你三千遍");
bos.newLine();换行标记
}
long e = System.currentTimeMillis();
System.out.println(e-s);
bos.flush();
bos.close();