using System.IO; StreamWriter writer = new StreamWriter("myfile.txt"); writer.WriteLine("Hello World!"); writer.Close();
using System.IO; StreamWriter writer = new StreamWriter("myfile.txt", true); writer.WriteLine("This line will be appended to the end of the file"); writer.Close();In this example, we create a new StreamWriter object, but this time we pass in a second argument of true. This tells the StreamWriter to append any text we write to the end of the file, rather than overwriting the file. We then write a line of text to the file and close the StreamWriter. The System.IO StreamWriter class is part of the .NET Framework, which is a package library developed by Microsoft.