code: public static File ensureParentDir(File file) {
          if (file != null && !file.getParentFile().isDirectory() && !file.getParentFile().mkdirs()) {
              throw new IllegalStateException("Can't create directory \"" + file.getParent() + "\".");
          }
          return file;
      }
docs: Ensure that the parent directory exists for the specified file.
  <p>
  This will attempt to create the parent directory if it does not exist yet.
  
  @param file The file verify directory existence for.
  @return The specified file.
  @throws IllegalStateException in case the parent directory did not yet exist and could not be created either.