this.治疗完毕

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#删除文本文件指定的内容

FileStream fs = new FileStream("这里是你的txt路径",FileMode.Open,FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs,Encoding.Default);
string content = sr.ReadToEnd();//这个就是文本内容
content = content.Replace("你要删除的文本","");//这里的删除是把你不要的字符串替换成空串
StreamWriter sw = new StreamWriter(fs,Encoding.Default);
sw.Write(Content);
sw.Close();

 

posted on 2018-05-31 19:07  this.治疗完毕  阅读(2182)  评论(0)    收藏  举报