Mega Code Archive

 
Categories / Ruby / File Directory
 

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.