日期:2014-05-18  浏览次数:20858 次

c#.net如何将记录写入到指定文本文件中?
C# code

private void SaveToFile()
{
            string result = 
                this.Barcode1 + "," +
                this.Barcode2 + "," +
                this.SNoCount + "," +
                this.TimeStamp;
}


我想把result里的记录写入到指定文本文件中,应该如何做?

------解决方案--------------------
System.IO.File.WriteAllText("my.txt", result);
------解决方案--------------------
C# code
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\logfile.txt",true);
sw.WriteLine(result);
sw.Close();

------解决方案--------------------
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\logfile.txt",true);
sw.WriteLine(result);
sw.Flush();
sw.Close();

or

File.WriteAllText("c:\text.txt",text);
------解决方案--------------------
探讨
我在file下面没有找到writeAllText这个方法吗?
IO包已经加了