Ruby program to read lines from the existing file
# Open an existing file.
fobj = File.new("MyFile.txt", "r");
# Read the values as an array of lines.
print(fobj.readlines());
# Close file object
fobj.close();
Output:
["Sample Text1\n", "Sample Text2\n", "Sample Text3\n", "Sample Text4"]
