如何使用File.WriteAllText但不要覆盖旧文本?

时间:2015-01-21 11:28:59

标签: c#-4.0

我想将所有数据从我的csv

返回到txt文件
string fileName = "../../TechFiles/";
List<string> listA = new List<string>();

using (var reader = new StreamReader(ConfigurationManager.AppSettings["ConfigurationSource"]))
{
    var hdr2 = "2012-05-09 12:52:00";
    var hdr1 = "Account";

    while (!reader.EndOfStream)
    {
        var line = reader.ReadLine();
        var values = line.Split(',');


        listA.Add(values[0]);
    csv = new StringBuilder();
newLine = string.Format("HDR {0} {1}\r\n{2}{3}" , hdr1,line, Environment.NewLine);
        csv.Append(newLine);

        File.WriteAllText(String.Format("{0}{1}", fileName, values[4] + ".txt"), csv.ToString());
    }
}

1 个答案:

答案 0 :(得分:2)

使用File.AppendAllText

File.AppendAllText(String.Format("{0}{1}", fileName, values[4] + ".txt"), csv.ToString());