I was trying to read a file in Prism but I do not find the correct function:
local arquivo = 'arquivo.txt'
imprima(arquivo)
On moon, it would be something like local file = 'file.txt'; print(file);
.
I was trying to read a file in Prism but I do not find the correct function:
local arquivo = 'arquivo.txt'
imprima(arquivo)
On moon, it would be something like local file = 'file.txt'; print(file);
.
The code below reads the entire contents of a file:
arquivo = 'arquivo.txt'
handle = io.open(arquivo, "r")
conteudo = handle:read("*a")
handle:close()
print(conteudo)
If you want to handle errors (recommended!), use something like
handle,message = io.open(nome, "r")
if handle==nil then error(message) end
In Prism the code is similar, just translate keywords, method names and options:
arquivo = 'arquivo.txt'
handle = es.abra(arquivo, "leitura")
conteudo = handle:leia("*t")
handle:feche()
imprima(conteudo)