打开现有文件,添加一行

我想打开一个文本文件,在其上添加一行,然后关闭它。



慕标琳琳
浏览 357回答 4
4回答

手掌心

您可以使用File.AppendAllText:File.AppendAllText(@"c:\path\file.txt", "text content" + Environment.NewLine);

ABOUTYOU

using (StreamWriter w = File.AppendText("myFile.txt")){  w.WriteLine("hello");}

BIG阳

或者你可以使用 File.AppendAllLines(string, IEnumerable<string>)File.AppendAllLines(@"C:\Path\file.txt", new[] { "my text content" });
打开App,查看更多内容
随时随地看视频慕课网APP