//写入(采用using使用完就放弃)
using (StreamWriter sw = new StreamWriter("name.txt", true))//true是追加append
{
sw.WriteLine(textContent.Text);
}
修改文件内容:
string strFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, @"文件路径\test.txt");
if (File.Exists(strFilePath))
{
string strContent = File.ReadAllText(strFilePath);
strContent = Regex.Replace(strContent, "将要被修改的内容", "修改后的内容");
File.WriteAllText(strFilePath, strContent);
}