How can I open up a file, read it until it finds a certain line and then replace that one line with some other text.

What I was thinking was open up two files, one for reading and for writing and just basically copy that file except for that one line but this method is slow with a big file (which is what I'm going to be using). Anybody have a different method? Please reply if so.