Path.writeText

void writeText(string content, string encoding = "utf-8", string errors = "strict", string newline = null, bool atomic = false) const

Writes text to the file (overwrites) with configurable encoding, newline handling, and optional atomic replace. Modeled after Python's pathlib.Path.write_text.

Parameters

contentThe text content to write.
encodingThe name of the text encoding to encode with. Supported: "utf-8" (aliases: "utf8").
errorsError handling on encode. For UTF-8 this is mostly irrelevant; kept for API parity. Accepted values: "strict" (default), "replace", "ignore".
newlineControls newline translation before writing: - null (default): translate "\n" to platform default ("\r\n" on Windows, "\n" elsewhere). - "": no translation; write content as-is. - one of "\n", "\r\n", "\r": translate "\n" to the given style.
atomicIf true, perform an atomic write by writing to a temporary file in the same directory and renaming over the target.