you are in: codestackercodes [RSS]reads an entire file as string

reads an entire file as string Delicious Email

show/hide lines
   1  def get_file_as_string(filename)
   2    data = ''
   3    f = File.open(filename, "r") 
   4    f.each_line do |line|
   5      data += line
   6    end
   7    return data
   8  end
   9  
  10  test = get_file_as_string 'myfile.txt'
  11  puts test
created by leozera — 01 November 2008 — get a short url — tags: ruby string embed

Comments



We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image