James Edward Gray II wrote: > On Aug 17, 2005, at 10:30 AM, Julian Leviston wrote: > >> Hi. >> >> Just wondering if there's a simpler way to do this? >> >> file = File.open("/usr/blah/1.txt") do | file | >> while line = file.gets >> the_string += line >> end >> end >> >> In other words, open a file, read the contents into a string called >> the_string > > file_contents = File.read("/usr/blah/1.txt") I was tempted to say "of course there is". It's so typical Ruby. :-) Btw, a remark to the OP's algorithm: IMHO this one is more efficient since it does not create new String objects all the time: file = File.open("/usr/blah/1.txt") do | file | s = "" while line = file.gets s << line end s end Note also that you might get nil instead of the empty string in your example if reading from an empty file (untested). But of course the one liner is even more efficient. :-) Kind regards robert