public static void deleteRecursively(Path rootDir) throws IOException {
    if (rootDir == null || !Files.exists(rootDir)) {
      return;
    }
    Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        Files.delete(file);
        return FileVisitResult.CONTINUE;
      }
      @Override
      public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
        Files.delete(dir);
        return FileVisitResult.CONTINUE;
      }
    });
  }
public static void deleteRecursively(Path rootDir) throws IOException {
    if (rootDir == null || !Files.exists(rootDir)) {
      return;
    }
    Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        Files.delete(file);
        return FileVisitResult.CONTINUE;
      }
      @Override
      public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
        Files.delete(dir);
        return FileVisitResult.CONTINUE;
      }
    });
  }
public static void deleteRecursively ( Path rootDir ) throws IOException { if ( rootDir == null || ! Files . exists ( rootDir ) ) { return ; } Files . walkFileTree ( rootDir , new SimpleFileVisitor < Path > ( ) { @ Override public FileVisitResult visitFile ( Path file , BasicFileAttributes attrs ) throws IOException { Files . delete ( file ) ; return FileVisitResult . CONTINUE ; } @ Override public FileVisitResult postVisitDirectory ( Path dir , IOException exc ) throws IOException { Files . delete ( dir ) ; return FileVisitResult . CONTINUE ; } } ) ; }
Deletes the given path, and if it is a directory, all files and subdirectories within it.

@param rootDir directory to delete
@throws IOException if any error occurs while deleting files or directories
Deletes the given path and if it is a directory all files and subdirectories within it .