public void copyFile(String formPath,String toPath){
File file1 = new File(formPath);//源文件路径
File file2 = new File(toPath);//目标文件路径
String fileName = file1.getName();
double fileSize = (file1.length())/1024/1024;
System.out.println("***********************文件属性×××××××××××××××××××××××××");
System.out.println("源文件路径:"+formPath);
System.out.println("目标文件路径:"+toPath);
System.out.println("文件名:"+fileName);
System.out.println("文件大小:"+fileSize+"MB");
try {
FileInputStream fin = new FileInputStream(file1);
FileOutputStream fout = new FileOutputStream(file2);
int len = fin.read();
System.out.println("开始复制.....");
long startTime = System.currentTimeMillis();//开始时间
while(len != -1){
fout.write(len);
len = fin.read();
}
long endTime = System.currentTimeMillis();//结束时间
System.out.println("文件复制完成,公耗时:"+(endTime-startTime)+"ms");
//关闭流
fin.close();
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
}