Path.readText

string readText(string encoding = "utf-8", string errors = "strict", string newline = null) const

Reads the contents of the file as text with configurable decoding and newline handling, inspired by Python's pathlib.Path.read_text.

Parameters

encodingThe name of the text encoding to decode with. Currently only "utf-8" (and aliases: "utf8", "UTF-8") is supported. Defaults to UTF-8.
errorsError handling policy for decode errors: - "strict" (default): throw on invalid byte sequences. - "replace": replace malformed sequences with U+FFFD (replacement char). - "ignore": skip malformed sequences silently.
newlineNewline normalization control during read: - null (default): perform universal newline translation ("\r\n" and "\r" are normalized to "\n"). - "": do not modify newlines (return data as in file after decoding). - one of "\n", "\r\n", "\r": normalize all newline variants to the given style.

Returns

The decoded file contents as a string.

Throws

If the path is not a file, unsupported encoding is requested, or when

errors=="strict" and malformed input is encountered.