Heartly
Heartly

Reputation: 75

How does a text editor insert text?

Suppose I wrote a letter in notepad and I saved it as letter.txt. Then I realized that I forgot to say one matter in that letter. So I opened letter.txt using any text editor such as Notepad, Wordpad or something. Now I inserted the letters which I want to say in this letter at the middle of the file. How does it work?

Example: Here is a message:

" Hi, How are you. Today i want to meet you. Thank you.

It is actually stored in memory like this:

"Hi,\nHow\0are\0you.\0TodayToday\0i\0want\0to\nmeet\0you.\nThank\0you.

Now I want to add I am fine after How are you. How does it work? How is it added in the middle of the file? how are the other words not overwritten? What is the process behind it?

Upvotes: 4

Views: 1318

Answers (1)

Roy Dictus
Roy Dictus

Reputation: 33139

For small files, text editors just read the whole file in memory. When you modify the text, the text editor modifies the in-memory version. Then when you save, the text editor overwrites the original file with the new contents -- so the whole file is overwritten, and the text is written to the file as-is without any references or other tricks.

Upvotes: 1

Related Questions