public static void copy ( final Path source , final Path dest ) throws IOException { if ( Files . exists ( source ) ) { Files . walkFileTree ( source , new SimpleFileVisitor < Path > ( ) { @ Override public FileVisitResult visitFile ( final Path file , final BasicFileAttributes attrs ) throws IOException { Files . copy ( file , resolve ( dest , relativize ( source , file ) ) ) ; return super . visitFile ( file , attrs ) ; } @ Override public FileVisitResult preVisitDirectory ( final Path dir , final BasicFileAttributes attrs ) throws IOException { Files . createDirectories ( resolve ( dest , relativize ( source , dir ) ) ) ; return super . preVisitDirectory ( dir , attrs ) ; } } ) ; } }
Copies a source to a destination works recursively on directories .