Writing a text file without overwriting, it is in C #

I would like to know if it is possible to write in a text file without overwriting its current contents and without creating or combining lists of strings, etc. So let's say that I run the program once and I write Hello, and when I start I write everything again, so txt now has Hello Everyone. Moreover, does anyone know how to read only a specific block of a line from a file, for example, from, to, or from Dear, with best wishes, etc. Thanks a lot! Hope my question is clear enough.

+4
source share
3 answers

To add text to a file, you can use the File.AppendText or File.AppendAllText .

+14
source

You can open the file in Append Mode, which will create the file if it does not exist, and add it if that happens.

http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx

As for the second part of the question, it depends on how big the file I am assuming. If it were small, I would read all of this and consider it for the line or block that I needed.

+2
source

Using:

  System.IO.File.AppendAllText(string path, string contents) 
+1
source

Source: https://habr.com/ru/post/1342712/


All Articles