public static void copyDir(File srcDir, File destDir) throws Exception {
destDir = new File(destDir, srcDir.getName());
if (!destDir.exists()) {
destDir.mkdir();
}
File[] srcDirFiles = srcDir.listFiles();
for (File fileOrDir : srcDirFiles) {
if (fileOrDir.isDirectory()) {
copyDir(fileOrDir, destDir);
} else {// 是文件就IO拷贝
FileInputStream fis = new FileInputStream(fileOrDir);
File destFilePath = new File(destDir, fileOrDir.getName());
FileOutputStream fos = new FileOutputStream(destFilePath);
byte[] byteArr = new byte[1024 * 10];
int len = 0;
while ((len = fis.read(byteArr)) != -1) {
fos.write(byteArr, 0, len);
}
fis.close();
fos.close();
}
}
}
}
|
|