函数名

io.open(path,mode)

函数介绍

方法名称:打开一个文件

参数说明:
path:字符串类型表示要打开的文件路径

mode:文件打开的模式,如下

"r":读模式 (默认);

"w":写模式;\r\na: 添加模式;

"r+":更新模式,所有之前的数据将被保存

"w+":更新模式,所有之前的数据将被清除

"a+":添加更新模式,所有之前的数据将被保存,只允许在文件尾进行添加

"b":某些系统支持二进制方式


返回值:文件句柄,失败则返回nil+错误信息

函数例子

local file = io.open("/mnt/sdcard/test.txt", mode)

print(file:write("123", "a"))

file:close()

local file = io.open("/mnt/sdcard/test.txt", "r+")

print(file:read("*a"))

file:close()