string path =@"c:\temp\MyTest.txt";// This text is added only once to the file.if(!File.Exists(path)){// Create a file to write to.string createText ="Hello and Welcome"+ Environment.NewLine;
File.WriteAllText(path, createText, Encoding.UTF8);}// This text is always added, making the file longer over time// if it is not deleted.string appendText ="This is extra text"+ Environment.NewLine;
File.AppendAllText(path, appendText, Encoding.UTF8);
string path =@"E:\VTK\MyTest.csv";// This text is added only once to the file.if(!System.IO.File.Exists(path)){// Create a file to write to.string createText ="时间,耗时"+ Environment.NewLine;
System.IO.File.WriteAllText(path, createText, Encoding.UTF8);}// This text is always added, making the file longer over time// if it is not deleted.int x =0;TryGetInputParam("in_2",out x);string appendText = DateTime.Now.ToString("yyyy:MM:dd:HH:mm:ss:fff")+","+x.ToString()+ Environment.NewLine;
System.IO.File.AppendAllText(path, appendText, Encoding.UTF8);