import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Demo7 {
public static void main(String[] args) throws Exception{
File srcFile = new File("D:\\aaa"); // 源目录
File destFile = new File("f:\\bbb"); // 目的目录
if (! destFile.exists()) {
destFile.mkdir();
}
copy(srcFile, destFile);
}
public static void copy(File srcFile, File destFile) throws Exception{
for (File file : fileArray) {
if (file.isFile()) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(destFile, file.getName())));
int len;
byte[] b = new byte[1024];
while ((len = bis.read(b)) != -1) {
bis.close();
bos.close();
} else {
File newFolder = new File(destFile, file.getName());
if (!newFolder.exists()) {
newFolder.mkdir();
}
copy(new File(srcFile, file.getName()), new File(destFile, newFolder.getName()));
}
}
}
}
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Demo7 {
public static void main(String[] args) throws Exception{
File srcFile = new File("D:\\aaa"); // 源目录
File destFile = new File("f:\\bbb"); // 目的目录
if (! destFile.exists()) {
destFile.mkdir();
}
copy(srcFile, destFile);
}
public static void copy(File srcFile, File destFile) throws Exception{
File[] fileArray = srcFile.listFiles();
for (File file : fileArray) {
if (file.isFile()) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(destFile, file.getName())));
int len;
byte[] b = new byte[1024];
while ((len = bis.read(b)) != -1) {
bos.write(b, 0, len);
bos.flush();
}bis.close();
bos.close();
} else {
File newFolder = new File(destFile, file.getName());
if (!newFolder.exists()) {
newFolder.mkdir();
}
copy(new File(srcFile, file.getName()), new File(destFile, newFolder.getName()));
}
}
}
}