io.open

Opens a file

Prototype

f = io.open (filename, mode)

Description

Opens a file and returns a file handle for working with it.

Modes can be a string which is: If the file cannot be opened this function does not raise an error (unlike io.input and io.output) but returns 3 things: Thus a sensible thing to do is wrap the io.open call with an assert, as in the example:

f = assert (io.open ("test.txt", "r"))  -- open it
s = f:read ("*a")  -- read all of it
print (s)  -- print out
f:close ()  -- close it

Lua functions

Topics