public static void recursiveCopy ( File original , File destDir ) throws IOException { final String name = original . getName ( ) ; final File destFile = new File ( destDir , name ) ; if ( original . isDirectory ( ) ) { destFile . mkdir ( ) ; for ( File file : original . listFiles ( ) ) { recursiveCopy ( file , destFile ) ; } } else { final OutputStream os = new FileOutputStream ( destFile ) ; try { final InputStream is = new FileInputStream ( original ) ; copyStreamAndClose ( is , os ) ; } finally { // in case the input stream open fails safeClose ( os ) ; } } }
Recursively copy a file or directory from one location to another .