Use code block to insert string to a file : Text file « File Directory « Ruby






Use code block to insert string to a file


open('s.html', 'wb') do |f|
  f << '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'
  f << "\xe2\x98\xBA"
end

 








Related examples in the same category

1.
2.Use each method to loop through a text file
3.Read line from a text file
4.Output each line in a file and close it
5.Read a text file with File.read
6.Read a text file readlines
7.Replace string in a file