Using the append mode to create a program that appends a line of text to a file each time it's run: : File.new « File Directory « Ruby






Using the append mode to create a program that appends a line of text to a file each time it's run:


f = File.new("logfile.txt", "a")
f.puts Time.now
f.close

 








Related examples in the same category

1.File Modes Usable with File.new
2.File.new creates a new object of the class File using the method new.
3.You need to specify the full path for the file unless the file is in the current working directory.
4.File.open