using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ReplaceText { class Program { static void Main(string[] args) { //防止文本字符中有特殊字符。必须用Encoding.Default StreamReader reader = new StreamReader(@"a.hhp", Encoding.Default); String a = reader.ReadToEnd(); //将a.hhp文件中bb替换为cc。 a = a.Replace("bb", "cc"); //a.hhp重命名为b.hhp //防止文本字符中有特殊字符。必须用Encoding.Default StreamWriter readTxt = new StreamWriter(@"b.hhp", false, Encoding.Default); readTxt.Write(a); readTxt.Flush(); readTxt.Close(); reader.Close(); //b.hhp重命名为a.hhp,并删除b.hhp File.Copy(@"b.hhp", @"a.hhp", true); File.Delete(@"b.hhp"); } } }