当你编写这段代码时:
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" };
File.WriteAllLines(path, createText);
}
Run Code Online (Sandbox Code Playgroud)

现在我想将 richTextBox 内容的每一行保存到 .txt 文件的新行,如结果图像。我编写代码如下:
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.AppendText(textBox1.Text +"\n");
System.IO.File.WriteAllText(@"C:\Users\Mohammad_Taghi\Desktop\ab\a.txt", richTextBox1.Text + Environment.NewLine);
}
Run Code Online (Sandbox Code Playgroud)
但是,结果是
