In this tutorial you will learn how to print the contents of files.
Open a fileEdit
Printing the contents of a file is simple to do. To open a file you use the io.open function. Then with the file handle you call file:read() with this argument "*a". This makes it read all text in the file.
local file = io.open("script.lua", "r") local text = file:read("*a") -- The *a text makes it read the contents of the whole file. file:close() -- We are done reading the file. print(text) -- This is to print the contents of the file.