Using Explicit File Descriptor
file = io.open("sample.txt", "r") print(file:read()) file:close() file = io.open("sample.txt", "a") file:write("Hello world") file:close()
Using Implicit File Descriptor
file = io.open("sample.txt", "r") io.input(file) print(io.read()) io.close(file) file = io.open("sample.txt", "a") io.output(file) io.write("Hello world") io.close(file)