txt记事本删除某一条数据

//新的txt
var tempFile = _iHostEnvironment.WebRootPath + "\mgc1.txt";
File.AppendText(tempFile);
//查找不等于ceshi的数据
var linesToKeep = File.ReadLines(_iHostEnvironment.WebRootPath + "\mgc.txt").Where(x => x !=“ceshi”);
//写到新的txt
File.WriteAllLines(tempFile, linesToKeep);
//删除旧的txt
File.Delete(_iHostEnvironment.WebRootPath + "\mgc.txt");
File.Move(tempFile, _iHostEnvironment.WebRootPath + "\mgc.txt");

posted @ 2021-07-09 13:58  cv玲玲  阅读(166)  评论(0编辑  收藏  举报