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






Read line from a text file

file = File.new( "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"
file.close

 








Related examples in the same category

1.
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 File.read
6.Read a text file readlines
7.Replace string in a file