Type Function Library io.* Return value Object Revision Current Public Release (2018.3326) Keywords io, input, file See also io.output() io.read()
Sets the standard input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file.
This function returns a file handle of the opened file or the handle to the current input file.
io.input ( file ) |
Object. File to set as the standard input file. You must use system.pathForFile() to create a file name and path to the system.ResourceDirectory
, system.DocumentsDirectory
, system.ApplicationSupportDirectory
, system.TemporaryDirectory
, or system.CachesDirectory
constants.
local path = system.pathForFile( "data.txt" , system.DocumentsDirectory ) local tmp = io.input () -- Save current file handle io.input ( path ) -- Open new file in text mode print ( io.read () ) -- Read and display the file io.input ():close() -- Close the file io.input ( tmp ) -- Restore the previous file |