Document: Read Synchronous
Read the contents of a file selected through a document dialog. Use it to import text or binary data after the user selects a file. Decode the returned string separately when the contents are JSON or another structured format.
Luau
Document:Read() -> stringParameters
Call this method with a Document receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
This function takes no arguments.
Returns
stringThe file contents as a string. Reading a folder raises an error.
Usage notes
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 = openfiledialog()
if document then
local ok, settings, message = json.decodeSafe(document:Read())
if ok then
print(json.encodePretty(settings))
else
print("Not valid JSON:", message)
end
end