Reputation: 53
How would this be written to be on a single line?
in_file = open(from_file)
indata = in_file.read
Upvotes: 4
Views: 4764
Reputation: 103844
To read ONE line you can use File.readline
Given:
cat file
Line 1
Line 2
Line 3
Line 4
In Ruby:
f=File.open("/tmp/file")
p f.readline
# "Line 1\n"
Upvotes: 0
Reputation: 1849
File.read("/path/to/file")
It will read whole file content and return it as a result.
Upvotes: 10