函数:io.open 按模式打开文件

函数名称:按模式打开文件

函数功能:以字符串指定的模式打开文件

函数方法

file,msg = io.open(filename,mode)

参数 类型 必填 说明
filename string 需要打开的文件路径
mode string 打开模式,不写默认为 "r"

mode 参数介绍

参数 说明
"r" 读取模式(默认)
"w" 写模式
"a" 追加模式
"r+" 更新模式,所有以前的数据都保留
"w+" 更新模式,以前的所有数据都被删除
"a+" 追加更新模式,保留以前的数据,只允许在文件末尾写入
"b" 二进制方式
返回值 类型 说明
file userdata/nil 成功返回打开文件的句柄,失败返回 nil
msg string 返回报错信息

函数用例

file,msg = io.open("/mnt/sdcard/kazhu.txt")
if file then
    dialog("打开成功",5000)
    file:close()
else
    dialog("打开失败,失败原因:"..msg,5000)
end
Copyright 北京帮你玩科技有限公司 2022 all right reserved,powered by Gitbook该文章修订时间: 2023-08-22 17:18:28

results matching ""

    No results matching ""