lua文件读写操作
来源:互联网 发布:战网客户端mac版下载 编辑:程序博客网 时间:2024/06/05 20:36
--读取文件操作
local f = assert(io.open("config.txt",'r'))--[[r表示读取的权限(read),a表示追加(append),w表示写的权限(write),b表示打开二进制(binary)]]
local string = f:read("*all")--[[*all表示读取所有的文件内容,*line表示读取一行,*number读取一个数字,<num>表示读取一个不超过num长度的字符]]
f:close() --关闭流
print(string)
--封装成函数
local function read_files( fileName )
local f = assert(io.open(fileName,'r'))
local content = f:read("*all")f:close()
return contentend
local rlt = read_files("config.txt")
print(rlt)
local f = assert(io.open("ok.txt",'w'))f:write("welcome to lua\n cocos2d-x")f:write("aaaaaaaaa")f:close()local function write_content( fileName,content )local f = assert(io.open(fileName,'a'))f:write(content)f:close()endwrite_content("ok.txt","hello lua\n")local long_string = [[\n cocos2d-x and lua welcome to you]]write_content("ok.txt", long_string)
阅读全文
0 0
- lua文件读写操作
- Lua的文件读写操作
- lua文件操作(1)----基本读写
- Lua读写EXCEL文件
- lua文件读写
- Lua 文件读写
- lua文件读写
- lua文件读写
- lua读写文件
- lua 文件读写
- lua 读写文件
- lua 读写文件
- Lua文件读写详解
- lua文件读写
- lua 文件读写
- lua文件读写
- lua文件读写
- Lua读写txt文件
- 节点拖拽
- BootStrap数据表格,
- 隐藏Nginx服务版本号信息
- node环境升级
- Hdu 4622 Reincarnation 后缀数组/后缀自动机
- lua文件读写操作
- Python之函数练习题
- 程序员养成架构师之路
- matlab2c使用c++实现matlab函数系列教程-sqrt函数
- 选择标签中不包含指定标签的其他元素
- 编程范式13 笔记
- diff命令---待完善
- java代码转Smali代码
- material design 之 ripple(波纹)效果