Read line from a text file : Text file « File Directory « Ruby

Read line from a text file

file = "yourFile.txt" )
file.readline # => "Let me not to the marriage of true minds\n"
file.readline # => "Admit impediments. Love is not love\n"
file.readline # => "Which alters when it alteration finds,\n"


Related examples in the same category

2.Use each method to loop through a text file
3.Output each line in a file and close it
4.Use code block to insert string to a file
5.Read a text file with
6.Read a text file readlines
7.Replace string in a file