Lua读写文件代码示例
2018-10-12 14:08
1291 查看
读写文件的模式:
r - 读取模式w - 写入模式(覆盖现有内容)
a - 附加模式(附加在现有内容之后)
b - 二进制模式
r+ - 读取更新模式(现有数据保留)
w+ - 写入更新模式(现有数据擦除)
a+ - 附加更新模式(现有数据保留,只在文件末尾附加)
do --read data from file function readFile() local fileHandle = assert(io.open("test.txt", "r"), "not the file"); if fileHandle then local outData = fileHandle:read("*all"); print(outData); else print("false"); end fileHandle:close(errorInfo); end --write data to the file function writeFile(dataBuffer) local writeHandle = assert(io.open("write.txt", "a+"), "not the file"); if writeHandle then writeHandle:write(dataBuffer); print("true"); else print("false"); end writeHandle:close(); end local inputData = 0; repeat inputData = io.read(); --write the data from io writeFile(inputData); until inputData == '#' end
您可能感兴趣的文章:
相关文章推荐
- Python文件的读写和异常代码示例
- C语言 以字符串的形式读写文件详解及示例代码
- STM32读写TXT文件(可追加数据)的示例代码
- Java代码实现对properties文件有序的读写的示例
- android开发之Json文件的读写的示例代码
- Windows系统中C#读写ini配置文件的程序代码示例分享
- Java对xls文件进行读写操作示例代码
- python 文件读写模式r,r+,w,w+,a,a+的区别(附代码示例)
- C语言 以字符形式读写文件详解及示例代码
- java输出/输出——文件读写示例代码总结
- Python文件读写保存操作的示例代码
- C语言 文件的随机读写详解及示例代码
- CC2538 zigbee I2C示例代码读写AT24C02D eeprom
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- java高级---线程、网络、文件、流、序列化等代码示例
- 用Java实现FTP批量大文件上传下载代码及示例下载
- 文件服务器读写简单示例
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- php 生成自动创建文件夹并上传文件的示例代码
- lua 文件读写