开发者

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

I would like to know if it is possible to write in a text fil开发者_如何学运维e without overwriting its current contents and without creating or merging Lists of string etc. So lets say i run the program once and i write Hello , and when i run it again i write Everyone so the txt has now Hello Everyone. Moreover, does anyone know how to read only a specific block of line from a file, for example from , to , or from Dear to Best Regards etc. Thanks a lot in advance!!! I hope that my question is clear enough


To append text to a file you can use the methods File.AppendText or File.AppendAllText.


You can open the file in Append Mode, which will create the file if it doesn't exist, and append if it does.

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 is I guess. If it was small I'd read the whole thing in and examine it for the line or block I needed.


Use:

        System.IO.File.AppendAllText(string path, string contents)  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜