code: public static void verifyDirectoryCreatable(Path path)
        throws AccessDeniedException, NotDirectoryException {
  
      Preconditions.checkNotNull(path, "Null directory path");
      for (Path segment = path; segment != null; segment = segment.getParent()) {
        if (Files.exists(segment)) {
          if (Files.isDirectory(segment)) {
            // Can't create a directory if the bottom most currently existing directory in
            // the path is not writable.
            if (!Files.isWritable(segment)) {
              throw new AccessDeniedException(segment + " is not writable");
            }
          } else {
            // Can't create a directory if a non-directory file already exists with that name
            // somewhere in the path.
            throw new NotDirectoryException(segment + " is a file");
          }
          break;
        }
      }
    }
docs: Check whether the current process can create a directory at the specified path. This is useful
  for providing immediate feedback to an end user that a path they have selected or typed may not
  be suitable before attempting to create the directory; e.g. in a tooltip.
  
  @param path tentative location for directory
  @throws AccessDeniedException if a directory in the path is not writable
  @throws NotDirectoryException if a segment of the path is a file