File.truncate : truncate « File Directory « Ruby






File.truncate


filename = 'truncate.txt'
f = open(filename, 'w') do |f|
  f << 'this is a test.'
end
File.size(filename)               

File.truncate(filename, 30)
File.size(filename)               
open(filename) { |f| f.read }     

 








Related examples in the same category

1.Erase all existing content