函数:io.read 按模式读取文件

函数名称:按模式读取文件

函数功能:按指定模式读取文件

函数方法

file,msg=io.read(format)

参数 类型 必填 说明
format string 读取格式/读取的字节数,不写默认值 :"*l"
参数 说明
"*n" 读取一个数字
"*a": 从当前位置读取整个文件,若为文件尾返回空字串
"*l" 读取下一行的内容,若为文件尾返回 nil
number 读取指定字节数的字符,若为文件尾返回 nil;如果 number 为 0 则返回空字串;若为文件尾,则返回 nil
返回值 类型 说明
file userdata/nil 成功返回打开文件的句柄,失败返回 nil
msg string 返回报错信息

函数用例

file,msg = io.open("/mnt/sdcard/kazhu.txt")
if file then
    dialog("文件全部内容:"..file:read("*a"),5)
    file:close()
else
    dialog("打开失败,失败原因:"..msg,5)
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""