TextFile
Represents a text file handle.
Use this class to read and write plain text files.
Example
var f = TextFile("notes.txt", "w")
f.write("hello\n")
f.append("world\n")
var lines = TextFile("notes.txt").read_lines()
Constructors
TextFile(const string path) -> TextFile
Opens a text file in read mode.
Parameters
- path: File path.
Example
var f = TextFile("notes.txt")
TextFile(const string path, const string mode) -> TextFile
Opens a text file with an explicit mode.
Modes:
- "r": read-only, file must exist
- "r+": read/write, file must exist
- "w": read/write, create or overwrite
- "w-" or "x": read/write, create, fail if it exists
- "a": read/write, create if missing
Parameters
- path: File path.
- mode: File open mode.
Example
var f = TextFile("notes.txt", "w")
Members
| Name | Description |
|---|---|
| append | Appends text to the end of the file. |
| path | Returns the resolved file path. |
| read | Reads the entire file as text. |
| read_lines | Reads the file as a list of lines (line endings stripped). |
| write | Writes text to the file, truncating first. |
| write_lines | Writes a list of lines to the file, truncating first. |