【发布时间】:2016-08-28 18:42:43
【问题描述】:
我想将字符串写入文件。我的问题是我无法在文件中添加新行。
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(String.Format("{0}.txt", svDialog.FileName)))
{
writer.Write(String.Format("{0}\n\n{1}", this.currentRealWorldObj.Title, this.currentRealWorldObj.Description));
}
如您所见,我在 String.Format 方法中添加了 2 个新行 ("\n\n")。但是当我打开时没有添加行。如何添加它们?
【问题讨论】:
-
试试
File.WriteAllText(fileName, textToWrite);