public static void copyDirectory ( File srcPath , File dstPath ) throws IOException { if ( srcPath . isDirectory ( ) ) { if ( ! dstPath . exists ( ) ) { dstPath . mkdirs ( ) ; } String files [ ] = srcPath . list ( ) ; for ( int i = 0 ; i < files . length ; i ++ ) { copyDirectory ( new File ( srcPath , files [ i ] ) , new File ( dstPath , files [ i ] ) ) ; } } else { InputStream in = null ; OutputStream out = null ; try { in = new FileInputStream ( srcPath ) ; out = new FileOutputStream ( dstPath ) ; transfer ( in , out ) ; } finally { if ( in != null ) { in . close ( ) ; } if ( out != null ) { out . flush ( ) ; out . close ( ) ; } } } }
Copy directory .