code: public static boolean hasPrefix(String path, String prefix) throws InvalidPathException {
      String[] pathComponents = getPathComponents(path);
      String[] prefixComponents = getPathComponents(prefix);
      if (pathComponents.length < prefixComponents.length) {
        return false;
      }
      for (int i = 0; i < prefixComponents.length; i++) {
        if (!pathComponents[i].equals(prefixComponents[i])) {
          return false;
        }
      }
      return true;
    }
docs: Checks whether the given path contains the given prefix. The comparison happens at a component
  granularity; for example, {@code hasPrefix(/dir/file, /dir)} should evaluate to true, while
  {@code hasPrefix(/dir/file, /d)} should evaluate to false.
  
  @param path a path
  @param prefix a prefix
  @return whether the given path has the given prefix
  @throws InvalidPathException when the path or prefix is invalid