public void WriteContext(string Context,string path)
{
StreamWriter sw = new StreamWriter(path);
sw.Write(Context);
sw.Close();
sw.Dispose();
}
private string ReadContext(string path)
{
FileStream fs = new FileStream(path, FileMode.Open);
StreamReader sr = new StreamReader(fs);
string context = sr.ReadToEnd();
fs.Close();
sr.Close();
sr.Dispose();
fs.Dispose();
return context;
}
或:
//读取文本
StreamReader sr = new StreamReader(文本文件的路径);
string str = sr.ReadToEnd();
sr.Close();
//替换文本
str = str.Replace("E103","E103**");
//更改保存文本
StreamWriter sw = new StreamWriter(文本文件的路径,false);
sw.WriteLine(str);
sw.Close();