: Text file « File Directory « Ruby







opens text.txt and then passes the file handle into the code block as f.

File.open("text.txt") do |f|
  puts f.gets
end

 

Related examples in the same category

1.Use each method to loop through a text file
2.Read line from 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