/**
   * Creates a new text file with given contents at the given full path-list. If a text file already
   * exists at said path, overwrite it. In either case, return the new text file.
   *
   * @param pathList The full path of the new file as a list of file names in descending order from
   *     the root of the file system.
   * @param contents The text contents of the new file.
   * @return The newly written text file.
   * @throws IsADirectoryException If the user attempts to overwrite the root directory.
   * @throws NoSuchFileException If one of the new file's specified ancestors does not exist.
   * @throws NotADirectoryException If one of the new file's specified ancestors is a text file.
   * @throws IllegalFilenameException If the name of the new text file as specified by pathList
   *     contains any illegal characters.
   */
  public static TextFile createTextFile(String[] pathList, String newContents)
      throws FileException {
    try {
      // Attempt to create a new text file at the specified path.
      return new TextFile(pathList, newContents);

      // If a file already exists at said path, overwrite it if it's a text
      // file, but not if it's a directory.
    } catch (DuplicateFileException e) {
      File duplicateFile = e.getDuplicateFile();

      duplicateFile.overwrite(newContents);
      return (TextFile) duplicateFile;
    }
  }