[C#] How to Append a File in C#

The AppendText method creates a StreamWriter object that appends UTF-8 encoded text to an existing text file.

string fileName = @"C:\fileName.txt";
FileInfo filetoappend = new FileInfo(fileName);
using (StreamWriter sw = filetoappend.AppendText())
   sw.WriteLine("--------- Append Text Start ----------");
   sw.WriteLine("New author started");
   sw.WriteLine("a book on Files Programming ");
   sw.WriteLine("using C#");
   sw.WriteLine("--------- Append Text End ----------");
// Read all text
string readText = File.ReadAllText(fileName);
Xem thêm  [C#] How to Copy a File in C#

You may also like...

3 Responses

  1. GuQin says:

    Hello. impressive job. I did not expect this. This is a great story. Thanks!

  2. hgf says:

    Your style is so unique compared to other people I’ve read stuff from.
    I appreciate you for posting when you’ve got
    the opportunity, Guess I will just bookmark this blog.

  1. 03/03/2019

    […] [C#] How to Append a File in C# […]

Leave a Reply

Your email address will not be published. Required fields are marked *