Ruby program to read the specified number of characters from the existing file
# Open an existing file.
fobj = File.new("MyFile.txt", "r");
# Read 5 character from "MyFile.txt" file.
print "File Text: ",fobj.sysread(5);
# Close file object
fobj.close();
Output:
File Text: Sampl
