Document: Write Synchronous
Replace the contents of the selected file with the supplied string. Use it to update a document you already have a handle for. This replaces the complete contents, so use Append when existing text must be retained.
Luau
Document:Write(contents: string) -> ()Parameters
Call this method with a Document receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
contents | string | Contents as a Luau string. The string may contain text or binary bytes. |
Returns
()This function returns no values.
Usage notes
The document must represent a file. Writing to a folder raises an error.
Document is a handle returned by a file dialog or a folder method. Call its methods with a colon, for example document:Read(). After Delete succeeds, that handle is invalid and further method calls raise an error.
Example
Luau
local document = savefiledialog("Draft", { suggestedName = "example-note.txt" })
if document then
document:Write("Revised draft")
print(document:Read()) -- Revised draft
end