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")

最新文章

  1. C# 超时工具类 第二版
  2. Linux小知识积累
  3. java安全沙箱(四)之安全管理器及Java API
  4. 如何使用SSL pinning来使你的iOS APP更加安全
  5. CodeForces 454C Little Pony and Expected Maximum
  6. seafile
  7. SQL 数据库表标识列初始化 DBCC
  8. 将string转化为char*的方法
  9. hdu 1561 The more, The Better_树状dp
  10. 2015第6周三ztree的使用
  11. HBase篇--初始Hbase
  12. Linux中安装nodejs及插件
  13. nginx-2-nginx的反向代理
  14. js高阶函数map和reduce
  15. Facebook's React vs AngularJS: A Closer Look
  16. Unity3D学习笔记(二十五):Json
  17. L1-017 到底有多二
  18. 逻辑斯蒂回归(Logistic Regression)
  19. TFS 切换登录用户的方法[转]
  20. 前端工程师的mysql笔记

热门文章

  1. ucos-ii的任务调度机制
  2. USB设备驱动概述
  3. Struts 有哪些常用标签库
  4. Java中的List转换成JSON报错(一)
  5. Java序列化机制和原理及自己的理解
  6. freemarker自定义标签(二十一)
  7. monkeyrunner_获取apk的包名和activity名
  8. StringBuilder的实现与技巧(转)
  9. 从0开始整合SSM框架-1.mybatis
  10. numpy使用总结