how to write content in a Specific position in a File

前端 未结 5 1165
北海茫月
北海茫月 2020-11-29 10:07

Suppose I have a file named abhishek.txt and that contains the following line

I am , and what is your name.

Now I want to write

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 10:46

    Generally speaking you need to read the old file, modify the contents in memory and write it back out again.

    There are many options here, as to whether you read the file all at once, or a small piece at a time, whether you replace the existing file, etc, but this is generally the pattern to use.

提交回复
热议问题