实现文件复制功能
filepath 原路径
filepathback 将要复制的新路径
第一步 : copyFile(filepath,filepathback);
//复制文件 开始
第二步 public void copyFile(String filepath1,String filepath1back){
// 1.提供读入和写入的文件
File f1 = new File(filepath1);
File f2 = new File(filepath1back);
// 2.提供相应的流对象
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(f1);
fos = new FileOutputStream(f2);
// 3.实现复制
byte[] b = new byte[200];
int len;
while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}