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)


References

  1. https://www.tutorialspoint.com/lua/lua_file_io.htm
  2. https://www.lua.org/pil/21.2.html


티스토리 툴바