code: protected boolean deleteIfExistsRecursively(Path path) throws IOException {
          try {
              return Files.deleteIfExists(path);
          }
          catch (DirectoryNotEmptyException ex) {
              //do recursive delete
              Files.walkFileTree(path, 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;
                  }
              });
              return true;
          }
      }
docs: Deletes the file or directory recursively if it exists.
  
  @param path
  @return
  @throws IOException