lua向文件中写入数据,进行记录
2024-10-19 00:25:23
function readfile(path)
local file = io.open(path, "r")
if file then
local content = file:read("*a")
io.close(file)
return content
end
return nil
end function writefile(path, content, mode)
mode = mode or "w+b"
local file = io.open(path, mode)
if file then
if file:write(content) == nil then return false end
io.close(file)
return true
else
return false
end
end
--文件读写测试
local a = {x=,y=,z=}
local str = json.encode(a) --将lua表编码为json格式字符串
local path = cc.FileUtils:getInstance():getWritablePath()
path = path..filename --得到可读写文件的路径
writefile(path,str,r) --将数据写入文件
local b = readfile(path) --从文件中读取数据
printf(b)
end 2. 文件操作示例代码
local path = cc.FileUtils:getInstance():getWritablePath()
cc.FileUtils:getInstance():writeToFile({key="value"}, paht.."filename") --读取数据的方式
print(ret.key)
lcoal ret = cc.FileUtils:getInstance():getValueMapFromFile(Path.."filename") --读取数据的方式2
print(str)
local str = cc.FileUtils:getInstance():getStringFromFile(path.."filename")
最新文章
- C# 超时工具类 第二版
- Linux小知识积累
- java安全沙箱(四)之安全管理器及Java API
- 如何使用SSL pinning来使你的iOS APP更加安全
- CodeForces 454C Little Pony and Expected Maximum
- seafile
- SQL 数据库表标识列初始化 DBCC
- 将string转化为char*的方法
- hdu 1561 The more, The Better_树状dp
- 2015第6周三ztree的使用
- HBase篇--初始Hbase
- Linux中安装nodejs及插件
- nginx-2-nginx的反向代理
- js高阶函数map和reduce
- Facebook's React vs AngularJS: A Closer Look
- Unity3D学习笔记(二十五):Json
- L1-017 到底有多二
- 逻辑斯蒂回归(Logistic Regression)
- TFS 切换登录用户的方法[转]
- 前端工程师的mysql笔记