FANDOM


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.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.