pull out the first two lines of the example file : gets « File Directory « Ruby






pull out the first two lines of the example file


File.open("text.txt") do |f|
  2.times { puts f.gets }
end

 








Related examples in the same category

1.Open a file stream, and then retrieve each line in order with the IO method gets.
2.use the gets statement of the class File.