Created
October 24, 2012 09:36
-
-
Save aoisensi/3945139 to your computer and use it in GitHub Desktop.
folder copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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