JAVA复制一个目录(包括所有子文件和目录)至当前目录
package com.qf.g_hmwk;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 实现文件夹的拷贝-----多层子目录-多种类型的文件
*
* @author Zhouzilong
* @date 2019年8月2日
*/
public class P1 {
public static void main(String[] args) throws IOException {
File src = new File("a");
File des = new File("a2");
copy(src,des);
}
private static void copy(File src, File des) throws IOException {
File[] srcs = src.listFiles();
if (!des.exists()) {
des.mkdirs();
}
if (!"a".equals(src.getName())) {
des = new File(des,src.getName());
des.mkdirs();
}
//循环复制每层目录的所有文件(注意:递归回来后上一层循环仍在继续)
for(File f:srcs) {
if (srcs == null) {
continue;