Lua讀檔案
--周遊檔案每一行,然後列印
y = 1
file = io.open("file_read_and_write.txt" ,"r");
for line in file:lines() do
print(y ..":".. line)
y = y + 1
end
file:close()
Lua寫檔案
--覆寫檔案所有内容,如果沒有該檔案,會自動建立
gFile = io.open("file_read_and_write.txt" ,"w");
gFile:write("78090890")
gFile:close()
--追加寫檔案,如果沒有該檔案,會自動建立
gFile = io.open("file_read_and_write1.txt" ,"a");
gFile:write("\nppppppppppp")
gFile:close()