File writing

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!

···

--
Posted via http://www.ruby-forum.com/.

Justin To wrote:

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.

···

--
Posted via http://www.ruby-forum.com/\.

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

···

On Wed, Jun 25, 2008 at 11:48 AM, Justin To <tekmc@hotmail.com> wrote:

Thanks!
--
Posted via http://www.ruby-forum.com/\.

Thank you!

···

--
Posted via http://www.ruby-forum.com/.

Hi again, how do I delete an item?

···

--
Posted via http://www.ruby-forum.com/.

Justin To wrote:

Hi again, how do I delete an item?

...delete an item and take the now empty line away

···

--
Posted via http://www.ruby-forum.com/\.