-- 游戏包可写路径
local fileRoad = cc.FileUtils:getInstance():getWritablePath()
local fileName = fileRoad .. "test.lua"
-- 文件是否存在
local isExist = cc.FileUtils:getInstance():isFileExist(fileName)
-- 存在,则可读文件
if isExist then
local myfi = assert(io.open(fileName,"r"))
local content = myfi:read("*a")
myfi:close()
end
-- 重写(创建)文件
local myfi = assert(io.open(fileName,"w"))
local content = "test txt"
myfi:write(content)
myfi:close()
-- 重加载内存中的lua文件
local keyName = fileRoad .. "test"
package.loaded[keyName] = nil
package.loaded[keyName] = require(keyName)