Mega Code Archive

 
Categories / C# / File Stream
 

File AppendAllText Opens a file, appends the specified string to the file

using System; using System.IO; using System.Text; class Test {     public static void Main()     {         string path = @"c:\data.txt";         if (!File.Exists(path))         {             string createText = "Hello " + Environment.NewLine;             File.WriteAllText(path, createText);         }         string appendText = "extra text" + Environment.NewLine;         File.AppendAllText(path, appendText);         string readText = File.ReadAllText(path);         Console.WriteLine(readText);     } }