Type Function Library io.* Return value none Revision Current Public Release (2018.3326) Keywords io, close, file See also io.open() io.read()
Closes an open file handle. Equivalent to file:close()
. If a file handle is not specified, this function closes the default output file.
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 |