use the gets statement of the class File. : gets « File Directory « Ruby






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.

 








Related examples in the same category

1.Open a file stream, and then retrieve each line in order with the IO method gets.
2.pull out the first two lines of the example file