类型 函数 库 io.* 返回值 无 修订 版本 2024.3703 关键词 io, close, 文件 另请参阅 io.open() io.read()
关闭一个打开的文件句柄。等同于 file:close()
。如果没有指定文件句柄,此函数将关闭默认输出文件。
io.close( [file] )
-- Path for the file local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory ) -- Open the file handle local file, errorString = io.open( path, "r" ) if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Read data from file local contents = file:read( "*a" ) -- Output the file contents print( "Contents of " .. path .. "\n" .. contents ) -- Close the file handle io.close( file ) end file = nil