public static void copy_1()throws IOException//用了284毫秒
{
BufferedInputStream bufis = new BufferedInputStream(new FileInputStream("c:\\0.mp3"));
BufferedOutputStream bufos = new BufferedOutputStream(new FileOutputStream("c:\\1.mp3"));
int by = 0;
//int count=0;
while((by=bufis.read())!=-1)//此方法是先把流对象读到缓冲区里面去
{
//count++;
//System.out.print(count);
bufos.write(by);
}
bufos.close();
bufis.close();
}
public static void copy_2()throws IOException//用了46617毫秒
{
FileInputStream fi=new FileInputStream("c:\\0.mp3");
FileOutputStream fo=new FileOutputStream("c:\\1.mp3");
int by=0;
while((by=fi.read())!=-1)
{
//count++;
//System.out.print(count);
fo.write(by);
}
fi.close();
fo.close();
}
public static void copy_3()throws IOException//只用了20毫秒
{
FileInputStream fi=new FileInputStream("c:\\0.mp3");
FileOutputStream fo=new FileOutputStream("c:\\1.mp3");
int by=0;
byte[] buf=new byte[1024*1024];
while((by=fi.read(buf))!=-1)
{
//count++;
System.out.println(by);
fo.write(buf,0,by);
}
fi.close();
fo.close();
} |
|