Skip to content

Instantly share code, notes, and snippets.

@aoisensi
Created October 24, 2012 09:36
Show Gist options
  • Save aoisensi/3945139 to your computer and use it in GitHub Desktop.
Save aoisensi/3945139 to your computer and use it in GitHub Desktop.
folder copy
public static void directoryCopy(File dust, File source){
for(File sources:source.listFiles()){
if(sources.isFile()){
fileCopy(dust, sources);
} else {
File folder = new File(dust, sources.getName());
folder.mkdir();
directoryCopy(folder,sources);
}
}
}
public static void fileCopy(File dust, File source){
FileChannel srcChannel = null;
FileChannel destChannel = null;
try {
srcChannel = new FileInputStream(source).getChannel();
destChannel = new FileOutputStream(dust).getChannel();
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (srcChannel != null) {
try {
srcChannel.close();
} catch (IOException e) {
}
}
if (destChannel != null) {
try {
destChannel.close();
} catch (IOException e) {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment