wood burning stoves 2.0*
The moose likes Ruby and the fly likes Question with reading and editing lines in a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Question with reading and editing lines in a file" Watch "Question with reading and editing lines in a file" New topic
Author

Question with reading and editing lines in a file

Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
The idea is to read a line from a file ... parse it and put it back in. The code I'm using now is not working ... it's deleting the entire file.


I assume I'm doing something wrong I just don't know what ... any ideas?


("Anger is not an emotion, its a symptom of fear.")
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

If you install the Facets gem (the command: "gem install facets") it can be as easy as:


Facets adds the rewrite method to File which makes it easy to do what you want.


A good workman is known by his tools.
Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
That's pretty sweet Marc. What I ended up doing was reading the entire file into an array and editing the lines there then re-writing the file .... however what I wanted to do was exactly what you just should me. I will have to play around with that snippet of code. Thanks for showing me.
 
wood burning stoves
 
subject: Question with reading and editing lines in a file