inserting into a file

S

Sai Krishna M

I want to insert a string in a file after a particular line.

I thought of using seek() function but on opening the file in append
mode the seek value is undone.
One crude idea i had was to read the file in a list and insert the
string correspondingly.

Is there any other way to do this?
Please help...

Sai krishna M
 
L

Larry Bates

Sai said:
I want to insert a string in a file after a particular line.

I thought of using seek() function but on opening the file in append
mode the seek value is undone.
One crude idea i had was to read the file in a list and insert the
string correspondingly.

Is there any other way to do this?
Please help...

Sai krishna M
No "magic" way to insert lines. If file is small, read into
memory, insert line, write to disk. If it is large, read and
write lines to secondary file, insert line, read remaining lines,
delete old file and rename to new file.

-Larry Bates
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top