Read a text file with File.read : Text file « File Directory « Ruby
- Ruby
- File Directory
- Text file
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