public void copyFile(String AbsolutePath,String destAbsolutePath){
FileInputStream fis=null;
FileOutputStream fos=null;
long start = System.currentTimeMillis();
try {
File file = new File(AbsolutePath);
File dest = new File(destAbsolutePath);
fis = new FileInputStream(file);
fos = new FileOutputStream(dest);
byte[] arr =new byte[1024];
int len;
//调用读取方法时候,一定要在形参内传入数组数据,才能进行读取
while ((len =fis.read(arr))!=-1){
fos.write(arr,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis!=null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
long end = System.currentTimeMillis();
System.out.println("复制成功");
System.out.println("花费的时间为"+(end-start));//413
}
实现一个文件的复制的方法
最新推荐文章于 2022-06-18 12:05:57 发布