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

9 lines
242 B
Ruby
Raw Permalink Normal View History

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