lua内蔵関数読み書きファイル
1212 ワード
lua
--io.open( , )
-- "w" "r" "a"
function writefile_test()
myfile=io.open("lisaisai.txt","w") --myfile
if myfile==nil then
print(" ")
else
myfile:write(string.format("%s:%s
","-- ",os.date()))
myfile:write(string.char(10)) -- "
"
myfile:write("--11111111111111
")
myfile:write("--lua
")
myfile:write("--lua
")
end
myfile:close() --
end
function readfile_test2()
myfile=io.open("lisaisai.txt","r") --myfile
if myfile==nil then
print(" ")
else
while true do
line=myfile:read("*l") --
print(line)
if line==nil then
break
end
end
end --end for
myfile:close()
end
function readfile_test1()
myfile=io.open("lisaisai.txt","r") --myfile
if myfile==nil then
print(" ")
else
for i in myfile:lines() do -- : , , , nil,
print(i)
end
end --end for
myfile:close()
end
writefile_test()
readfile_test1()
--readfile_test2()