Closing File Connections

io.close() closes the file! It’s often used with the Colon Operator shorthand to pass the file as the 1st argument.

local File = io.open("myFile.txt") File:close()

Files are automatically closed by Lua garbage collection to manage memory, but that takes an unpredictable amount of time to happen. It is always best to call close() explicitly.

 

Related pages