/*
编写一个程序,用于实现文件的备份,程序运行时的命令语法为:
java MyCopy (sourcefile) (destfile)
*/
import java.io.*;
class MyCopy2
{
public static void main(String[] args)
{
long start =System.currentTimeMillis();
FileInputStream fis=null;
FileOutputStream fos=null;
try
{
//文件字节输入流
fis=new FileInputStream("c:\\功夫熊猫.mkv");
//文件字节输出流
fos=new FileOutputStream("d:\\功夫熊猫1.mkv");
byte[] buf=new byte[1024];
// int i=bfis.read(buf,0,1024);
int i=0;
while((i=fis.read(buf))!=-1)
{
fos.write(buf,0,i);
// bfos.flush();
}
}
catch (IOException e)
{
throw new RuntimeException("文件复制失败");
}
finally
{
try
{
if(fis!=null)
fis.close();
}
catch (IOException e)
{
throw new RuntimeException("读取关闭失败");
}
try
{
if(fos!=null)
fos.close();
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
// bfis.close();
// bfos.close();
long end =System.currentTimeMillis();
System.out.println((end-start)+"毫秒");
}
}
|
|