public static void copyDir(final File src, final File dest) throws IOException {
dest.mkdirs();
File[] files = src.listFiles();
int j = files.length; // cache the length so it doesn't need to be looked up over and over in the loop
for (int i = 0; i < j; i++) {
File file = files[i];
if (file.isDirectory()) {
copyDir(file, new File(dest, file.getName()));
} else {
copyFile(file, new File(dest, file.getName()));
}
}
}
public static void copyFile(final File src, final File dest) throws IOException {
dest.getParentFile().mkdirs();
dest.createNewFile();
FileChannel sourceChannel = new FileInputStream(src).getChannel();
FileChannel targetChannel = new FileOutputStream(dest).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
}
dest.mkdirs();
File[] files = src.listFiles();
int j = files.length; // cache the length so it doesn't need to be looked up over and over in the loop
for (int i = 0; i < j; i++) {
File file = files[i];
if (file.isDirectory()) {
copyDir(file, new File(dest, file.getName()));
} else {
copyFile(file, new File(dest, file.getName()));
}
}
}
public static void copyFile(final File src, final File dest) throws IOException {
dest.getParentFile().mkdirs();
dest.createNewFile();
FileChannel sourceChannel = new FileInputStream(src).getChannel();
FileChannel targetChannel = new FileOutputStream(dest).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
}