Ruby 3 · Errors and files
Read a file
Read a whole file, or iterate lines without loading it all.
text = File.read("data.txt")
File.foreach("data.txt") { |line| puts line }
Ruby 3 · Errors and files
Read a whole file, or iterate lines without loading it all.
text = File.read("data.txt")
File.foreach("data.txt") { |line| puts line }
Was this page helpful?