package com.chinasoft;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class FolderCopy2 {
public static void main(String[] args) {
String oldPath = "c:/test";
String desPath = "c:/copyTest";
new FolderCopy2().copyFolder(oldPath, desPath);
}
public void copyFolder(String path, String path1) {
File file = new File(path);
File file1 = new File(path1);
if (!file.exists()) {
System.out.println(file.getName() + "源文件不存在");
}
byte[] b = new byte[(int) file.length()];
if (file.isFile()) {
try {
FileInputStream is = new FileInputStream(file);
FileOutputStream ps = new FileOutputStream(file1);
is.read(b);
ps.write(b);
} catch (Exception e) {
e.printStackTrace();
}
} else if (file.isDirectory()) {
if (!file1.exists()) {
file1.mkdir();
}
String[] list = file.list();
for (int i = 0; i < list.length; i++) {
this.copyFolder(path + "/" + list[i], path1 + "/" + list[i]);
}
}
}
}