文件操做一:替換文件中的字符string
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");
}
}it
using(FileStream fs = new FileStream("a.txt", FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(text);
}
}
文件