C# 修改记事本中指定的值

原文链接:http://blog.csdn.net/cout_sev/article/details/49304513

string path = @"D:\Users\Desktop\123";
string[] pathFile = Directory.GetFiles(path);
string con = "";
foreach (string str in pathFile)
{
    FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read);
    StreamReader sr = new StreamReader(fs);
    con = sr.ReadToEnd();
    con = con.Replace("内容", "替换内容");
    sr.Close();
    fs.Close();
    FileStream fs2 = new FileStream(str, FileMode.Open, FileAccess.Write);
    StreamWriter sw = new StreamWriter(fs2);
    sw.WriteLine(con);
    sw.Close();
    fs2.Close();
}
MessageBox.Show("转换完成");

你可能感兴趣的:(C#)