inserting into a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sai Krishna M

    #1

    inserting into a file

    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
    --
    I love Freedom
  • Larry Bates

    #2
    Re: inserting into a file

    Sai Krishna M wrote:
    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

    Comment

    Working...