9951 explained code solutions for 126 technologies


luaHow to read file


file = io.open('/var/www/examples/test.txt', 'r')
local data = file:read()
io.close(file)ctrl + c
io.open

opens file handler

/var/www/examples/test.txt

path to the file to open

'r'

open file in reading mode

file:read()

reads opened file content

data

variable will contain file content

io.close

closes file handler