RosettaCodeData/Task/Truncate-a-file/Ruby/truncate-a-file.rb

9 lines
242 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# Open a file for writing, and truncate it to 1234 bytes.
File.open("file", "ab") do |f|
f.truncate(1234)
f << "Killroy was here" # write to file
end # file is closed now.
# Just truncate a file to 567 bytes.
File.truncate("file", 567)