lua内置函数读写文件
来源:互联网 发布:c语言编程好的小程序 编辑:程序博客网 时间:2024/06/06 10:03
用lua内置函数读写文件--io.open(文件名,操作方式)--操作方式有"w" 写模式 "r"读模式 "a"追加模式function writefile_test()myfile=io.open("lisaisai.txt","w")--myfile相当于文件句柄 文件指针if myfile==nil thenprint("创建文件出错")elsemyfile:write(string.format("%s:%s\n","--文件创建时间",os.date()))myfile:write(string.char(10)) --换行 也可以直接写入"\n"换行myfile:write("--11111111111111\n")myfile:write("--lua文件操作测试\n")myfile:write("--lua文件操作测试\n")end myfile:close() --关闭文件endfunction readfile_test2()myfile=io.open("lisaisai.txt","r")--myfile相当于文件句柄 文件指针if myfile==nil thenprint("创建文件出错")elsewhile true doline=myfile:read("*l") --读到文件末尾返回一个空print(line)if line==nil thenbreakendendend --end for myfile:close()endfunction readfile_test1()myfile=io.open("lisaisai.txt","r")--myfile相当于文件句柄 文件指针if myfile==nil thenprint("创建文件出错")elsefor i in myfile:lines() do --功能:返回一个迭代函数,每次调用将获得文件中的一行内容,当到文件尾时,将返回nil,但不关闭文件print(i)endend --end for myfile:close()endwritefile_test()readfile_test1()--readfile_test2()
0 0
- lua内置函数读写文件
- 使用Delphi内置函数读写INI文件
- Lua内置函数大全
- 使用Delphi内置函数读写INI文件[转]
- 使用Delphi内置函数读写INI文件[转][二]
- Lua读写EXCEL文件
- lua文件读写
- Lua 文件读写
- lua文件读写
- lua文件读写
- lua读写文件
- lua 文件读写
- lua 读写文件
- lua 读写文件
- Lua文件读写详解
- lua文件读写
- lua 文件读写
- lua文件读写
- uboot下init_sequence_f函数之init_func_spi
- 金明的预算方案 (变形01背包)
- React-native 下拉弹框选择(根据网上省 市 区插件改写)
- Python 爬虫入门(三) HTTP协议请求方式
- Linux入门
- lua内置函数读写文件
- vuex中关于mapState,mapGetters,mapMutations,mapActions的作用
- JAVA基础
- appcompat误删后无法生产R.java
- Hive vs. HBase
- 如何利用eclipse在项目中找到某段代码的出现位置?
- 3月15 开始记录学习前端那些事
- 《将博客搬至CSDN》
- 使用 dbms_file_transfer 方式测试增量传输表空间XTTS