Cocos2d-Lua之文件操作
来源:互联网 发布:房屋设计软件下载 编辑:程序博客网 时间:2024/05/21 07:12
一、文件打开操作
格式:
file, msg = io.open("文件的绝对路径名", "打开方式") --打开方式有r, w, a, r+, w+, a+,跟C/C++的打开方式是一样的,返回文件和是否正确打开的信息
二、文件读取方式
格式:
file:read("*line") --读取文件中的一行,若缺省默认也是读取一行file:read("*all") --读取文件中的全部内容
三、文件的写入
格式:
file:write("要写入的内容")
四、示例
function fileRead() file, msg = io.open("D:\\test\\MyGame\\firstgame\\src\\app\\scenes\\filetest.txt", "r") if not file then print(msg) end --s = file:read("*all") repeat s = file:read() if(s ~= nil) then print(s) else break; end until false print(s)endfunction fileWrite() file, msg = io.open("D:\\test\\MyGame\\firstgame\\src\\app\\scenes\\filetest.txt", "a") file:write("hello world\n") file:flush() --刷新文件 file:close() --关闭文件endfileWrite() --先写入文件fileRead() --再读取文件
输出结果:
这里地方打印出了nil,有待考究。同样可以用file:read(“*all”)一次性全部读取出来。
0 0
- Cocos2d-Lua之文件操作
- quick-cocos2d-x(lua) 文件拷贝操作
- Cocos2d-Lua之Lua文件的加载与运行
- Cocos2d-x之文件操作
- quick-cocos2d-x lua 触摸事件、操作文件的实例
- cocos2d-x与lua数据传输操作之C++版ByteArray
- Cocos2d-Lua之函数
- Cocos2d-Lua之赋值
- Cocos2d-Lua之table
- Cocos2d-Lua之string
- Cocos2d-Lua之随机数
- 《Cocos2d-x-3.2 Lua-tests》文件详解 之 加速器
- cocos2d-x lua 位操作
- Cocos2d-x Lua基本操作
- (一)Cocos2d-x学习之文件操作
- [寒江孤叶丶的Cocos2d-x之旅_24]Cocos2d-x LUA 解析 Csv文件的方法
- Cocos2d-x 之Lua初学
- Cocos2d-X之LUA笔记
- 关于springmvc跨域
- 作业补做1
- Java 进行 RSA 加解密的例子
- K2数据库database
- 用成员函数还是用友元函数重载双目运算符?
- Cocos2d-Lua之文件操作
- 字符串末尾自动加上'\0'的情况
- SpringMVC详细示例实战教程
- 作业补做2
- bzoj 1507: [NOI2003]Editor (块状链表)
- Struts1内部原理详解
- No 'Access-Control-Allow-Origin' header is present on the requested resource
- Leetcode Single Number II
- Word 粘贴仅保留文本