class TestUnicode
{
public static void main(String[] args)
{
//计算通过字符流实现复制所耗费的时间
try{
long da1= (new Date()).getTime();
FileInputStream fis= new FileInputStream("E:\\复件 Q.骑士.txt");
BufferedReader bin = new BufferedReader(new InputStreamReader(fis,"Unicode"));//读取文件内容
PrintWriter pout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\复件 Q.骑士.txt"))));//向文件中写入内容
String s1;
while((s1 = bin.readLine())!=null)
{
pout.write(s1);
}
bin.close();
pout.close();
long da2= (new Date()).getTime();
System.out.println("通过字符流实现复制所耗费的时间:"+(da2-da1));
}catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}
//计算通过字节流实现复制操作所耗费的时间
try
{
long da3= (new Date()).getTime();
FileInputStream fin = new FileInputStream("E:\\Q.骑士.txt");
FileOutputStream fout = new FileOutputStream("D:\\Q.骑士.txt");
byte[] buffer = new byte[1024*2];
int bytelenth = fin.read(buffer);
while(bytelenth!=-1)
{
fout.write(buffer,0,bytelenth);
bytelenth = fin.read(buffer);
}
fin.close();
fout.close();
long da4= (new Date()).getTime();
System.out.println("通过字节流实现复制所耗费的时间:"+(da4-da3));
} catch(FileNotFoundException e1){
e1.printStackTrace();
}catch(IOException e2){
e2.printStackTrace();
}
}
} 作者: 袁冬梅 时间: 2012-3-23 00:43