110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.IO;
class Test
{
public static void Main()
{
//文件路径
string path = @"c:\temp\MyTest.txt";
// This text is added only once to the file.
if (!File.Exists(path))
{
return;
}
//读取文件内容
string readText = File.ReadAllText(path);
//将文件中的"old"替换成"new"
string newText=readText.Replace("old","new");
//将文件内容写入文件,如果文件已存在则覆盖原文件
File.WriteAllText(path, newText);
}
}