Ruby/File Directory/gets
Материал из Wiki.crossplatform.ru
Open a file stream, and then retrieve each line in order with the IO method gets.
file = File.new( "yourFile.txt" ) file.gets file.gets
pull out the first two lines of the example file
File.open("text.txt") do |f| 2.times { puts f.gets } end
use the gets statement of the class File.
file6 = File.new("C:\\Ruby\\Sample") str=file6.gets puts str # In this code, the file6.gets statement will pass the contents of the file Sample to the str variable. The puts str statement will output the contents to the screen.