Home >Backend Development >C++ >How Can I Add a Single Line to a Text File Without Overwriting It?
Append a single line of text to an existing text file
Goal: Append a line of text to an existing text file without overwriting the existing content.
Solution:
For this you can use the File.AppendAllText
method. This method accepts two parameters:
Example usage:
<code class="language-csharp">File.AppendAllText(@"c:\path\file.txt", "文本内容" + Environment.NewLine);</code>
Instructions:
Environment.NewLine
. This is necessary to create new lines in text files. Use File.AppendAllText
to conveniently add a line of text to an existing file without affecting its current content.
The above is the detailed content of How Can I Add a Single Line to a Text File Without Overwriting It?. For more information, please follow other related articles on the PHP Chinese website!