// 递归法复制多层文件、文件夹
public static void diguicopy(File file, File destnation) throws IOException {
// 在目的地创建该文件夹
File newfolder = new File(destnation, file.getName());
newfolder.mkdir();
// 获取文件对象数组
File[] files = file.listFiles();
// 遍历该对象数组
for (File f : files) {
if (f.isDirectory()) {
//递归
diguicopy(f, newfolder);
} else {
//高效字节数组缓冲流
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(new File(newfolder, f.getName())));
int b = 0;
byte[] by = new byte[1024];
while ((b = bis.read(by)) != -1) {
bos.write(by, 0, b);
}
bos.close();
bis.close();
}
}
}
}