您的位置:首页 > 编程语言 > C#

c# 修改文本文件内容后并保存(转自百度知道)

2013-10-17 14:43 459 查看
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐