All I want to do is get all the content from a local file and store it in a variable. How?
File.read(@icon.full_filename).each {|l| r += l}
only gives me a part of it. In PHP, I just used file_get_contents
.
Use File#readlines to Read Lines of a File in Ruby Newline character \n may be included in each line. We must be cautious when working with a large file, File#readlines will read all lines at once and load them into memory.
data = File.read("/path/to/file")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With