package cn.itcast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Char_Buffered_2Copy {
public static void main(String[] args) throws IOException {
long before = System.currentTimeMillis();
method1();// 315
// method2();//352
long after = System.currentTimeMillis();
System.out.println(after - before);
}
private static void method1() throws IOException {
FileReader fr = new FileReader("a.mp3");
FileWriter fw = new FileWriter("b.mp3");
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
int b;
while ((b = br.read()) != -1) {
bw.write(b);
}
br.close();
bw.close();
}
private static void method2() throws IOException {
FileReader fr = new FileReader("a.mp3");
FileWriter fw = new FileWriter("b.mp3");
BufferedReader br = new BufferedReader(fr);
BufferedWriter bw = new BufferedWriter(fw);
int len;
char[] chars = new char[1024];
while ((len = br.read(chars)) != -1) {
bw.write(chars, 0, len);
}
br.close();
bw.close();
}
}
|
|