函数: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("D:\工具\kazhu.txt")
if file then
   nLog("打开成功")
    file:close()
else
   nLog("打开失败,失败原因:"..msg)
end
Copyright 北京帮你玩科技有限公司 2024 all right reserved,powered by Gitbook该文章修订时间: 2025-03-04 15:43:41

results matching ""

    No results matching ""