Read a text file with File.read : Text file « File Directory « Ruby






Read a text file with File.read



# Put some stuff into a file.
open('sample_file', 'w') do |f|
  f.write("This is line one.\nThis is line two.")
end

File.read('sample_file')
# => "This is line one.\nThis is line two."

 








Related examples in the same category

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