Type Function Library io.* Return value Function (iterator) Revision Release 2021.3642 Keywords io, lines, file See also io.input()
Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file.
The function will open the file and iterate over all lines of the file. When the iterator function detects the end of file, it returns
io.lines() with no file is similar to
io.input():lines(); that is, it iterates over the lines of the default input file, except it does not close the file when the loop ends.
This function returns an iterator function that, each time it is called, returns a new line from the file.
io.lines( file )
local path = system.pathForFile( "data.txt", system.DocumentsDirectory ) for line in io.lines( path ) do print( line ) end