函数:io.type 判断句柄

优质
小牛编辑
127浏览
2023-12-01

函数名称:判断句柄

函数功能:判断是否为有效句柄

函数方法

bool = io.type(file)

参数类型必填说明
fileuserdata需要判断的文件句柄
返回值类型说明
boolstring“file“ - 一个打开的文件句柄,"closed file“ - 为一个已关闭的文件句柄,nil - 不是文件句柄

函数用例

file,msg = io.open("/mnt/sdcard/kazhu.txt")
bool = io.type(file)
if bool == "file" then
    dialog("是文件句柄",5000)
elseif bool == "closed file" then
    dialog("句柄已关闭",5000)
elseif bool == nil then
    dialog("不是文件句柄",5000)
end