替换文件中的字符

文件操作一:替换文件中的字符

string text = string.Empty;
using (FileStream fs = new FileStream("a.txt", FileMode.Open, FileAccess.Read))
{
using (StreamReader sr = new StreamReader(fs))
{
text = sr.ReadToEnd();
text=text.Replace("aaa", "bbb");
}
}

using(FileStream fs = new FileStream("a.txt", FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(text);
}
}

posted @ 2016-11-07 18:41  fireBeating  阅读(277)  评论(0编辑  收藏  举报