readFile 将指定文件中的内容按行读取
function readFile(path)
local file = io.open(path,"r");
if file then
local _list = {};
for l in file:lines() do
table.insert(_list,l)
end
file:close();
return _list
end
end
参数 |
类型 |
必填 |
说明 |
path |
string |
是 |
要读取文件的路径 |
返回值 |
类型 |
说明 |
list |
table/nil |
文件内容 |
函数用例
function readFile(path)
local file = io.open(path,"r");
if file then
local _list = {};
for l in file:lines() do
table.insert(_list,l)
end
file:close();
return _list
end
end
function file_exists(file_name)
local f = io.open(file_name, "r")
return f ~= nil and f:close()
end
bool = file_exists(userPath().."/lua/main.lua")
if bool then
list = readFile(userPath().."/lua/main.lua")
if #list > 0 then
for i=1, #list,1 do
dialog(list[i])
end
end
else
dialog("文件不存在",0)
end