Reading line by line

The file handle returned by io.open has a lines member function. This function will return an iterator that can be used to retrieve every line of the file using a loop. The following code demonstrates how to read an entire file, one line at a time:

file = io.open("data.txt")
lines = file:lines()
print("Contents of file:");
for line in lines do
print(" " .. line)
end
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.189.186