C#在不重写的情况下将文本添加到文本文件吗? [英] C# add text to text file without rewriting it?
本文介绍了C#在不重写的情况下将文本添加到文本文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下代码:
StreamWriter sw = new StreamWriter(File.OpenWrite(Path));
sw.Write("Some stuff here");
sw.Dispose();
此代码将文件内容替换为此处有东西",但是我想添加文本到文件中,而不是替换文本.我该怎么办?
This code replaces the contents of the file with "Some stuff here," however I would like to add text to the file rather than replacing the text. How would I do this?
推荐答案
您需要告诉要添加的StreamWriter
:
var sw = new StreamWriter(path, true);
File.OpenWrite
不支持追加.
File.OpenWrite
doesn't support appending.
这篇关于C#在不重写的情况下将文本添加到文本文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文