static public void copyDirTree ( String fromDirName , String toDirName ) throws IOException { File fromDir = new File ( fromDirName ) ; File toDir = new File ( toDirName ) ; if ( ! fromDir . exists ( ) ) return ; if ( ! toDir . exists ( ) ) { if ( ! toDir . mkdirs ( ) ) { throw new IOException ( "Could not create directory: " + toDir ) ; } } File [ ] files = fromDir . listFiles ( ) ; if ( files != null ) for ( File f : files ) { if ( f . isDirectory ( ) ) copyDirTree ( f . getAbsolutePath ( ) , toDir . getAbsolutePath ( ) + "/" + f . getName ( ) ) ; else copyFile ( f . getAbsolutePath ( ) , toDir . getAbsolutePath ( ) + "/" + f . getName ( ) ) ; } }
Copy an entire directory tree .