- Documentation
- Shared functions
- fileGetContents
Function
fileGetContents
Reads a whole file in one call. Accepts a file handle or a path (it then opens and closes the file itself).
Syntax
string fileGetContents(file/string fileOrPath [, bool verifyContents = true])Arguments
fileOrPathfile/string- A handle or a path.
verifyContentsbool, optional = true- For compatibility with existing scripts.
Returns
The file content, or false.
Example
local json = fileGetContents("config.json")
local config = json and fromJSON(json) or {}
See also
fileOpenOpens an existing file for reading and writing (or read-only). On the server the path is relative to the resource folder and cannot leave it. On the client it first looks for the script's own files (written withfileCreate), then for<file>files sent by the server - those are read-only;":other/file"points to another resource's file. Close the file withfileClosewhen done.fileReadReads the given number of bytes from the current position and moves the position. At the end of the file it returns an empty string. Binary data is returned unchanged.