From: Stefano Crocco Date: 2008-03-04T02:31:04+09:00 Subject: Re: Loading a file in a buffer... Alle Monday 03 March 2008, Zangief Ief ha scritto: > Hello everybody, > > I would like to load the exact content of a file in a buffer (with the > same carriage return). To do so, I had trying this: > > file = File.open('/home/my_file') > > To verify if that work normally, I had try to add this for display the > content of my_file: > > puts file > > But my_file was not been printed, and I got: # > > > If you know a way to do so, please help me :) > Thanks. > > Zang' To get the contents of a file, opening it is not enough. You need to explicitly read its contents. There are many methods which allow to access the contents of a file: read, readlines, each_line, each_byte, File.read, File.readlines, File.foreach (the last three are class methods). They're documented under class IO (from which File is derived). If you only need to read the contents of the file you don't need to use File.open at all, but simply use File.read: contents = File.read('/home/my_file'/) I hope this helps Stefano