File writing

J

Justin To

Hi, I know you can write to a file using 'w', but this erases all the
previous data. How can I add new items to an existing document without
losing the data?

Thanks!
 
T

Tim Hunter

Justin said:
Hi, I know you can write to a file using 'w', but this erases all the
previous data. How can I add new items to an existing document without
losing the data?

Thanks!

Use "a" instead of "w". That will Append new data to the end of the
file.
 
M

Michael Steinfeld

Hi, I know you can write to a file using 'w', but this erases all the
previous data. How can I add new items to an existing document without
losing the data?


filename = File.open("test","a") do |f|
f.puts "append to file";
f.close();
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top