Luart
Comprehensive Windows framework to develop in Lua
modules > sys > File > open

File : open ([mode], [encoding]) method

Open the file for read/write operations.

Parameters

mode

An optional string that indicates the kind of access when opening the file.

encoding

An optional string that indicates the encoding for read/write operations. By default, for read and append modes, encoding is auto-detected if not provided. For write modes, the default encoding value is utf8.

Return value

Returns the same File value if the operation succeeded or raises an error.

Example


local file = sys.File("Hello.txt")

-- open the file for writing, using default utf8 encoding
file:open("write")

file:write("Hello World")
file:close()