The method syswrite writes the contents of the file.
file4 = File.new("C:\\Ruby\\Sample", "r+") puts file4.sysread(20) file4.syswrite("ABCDEF") # write ABCDEF from the 21st character onward.