怎样改写txt文件?
我想改写硬盘上note.txt的文本文件中的某些指定文本,例如,在note.txt中找到字符串"filelist",并将其改写为字符串"gamelist"。应该使用什么方法?最好是。net的,谢谢!
------解决方案--------------------string content = File.ReadAllText(path);
content.Replace("","");
File.WriteAllText(path);
------解决方案--------------------C# code
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
tempStr = tempStr.Replace("filelist", "gamelist");//替换文本
File.WriteAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", tempStr, Encoding.GetEncoding("GB2312"));//写入txt
------解决方案--------------------