.net中file.replace 方法求助
发布网友
发布时间:2022-04-24 10:01
我来回答
共1个回答
热心网友
时间:2023-10-09 16:24
StreamReader sr = new StreamReader(@"file1.txt");
StreamWriter sw = new StreamWriter(@"file2.txt");
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
line = line.Replace("1234", "4321");
sw.WriteLine(line);
}
sr.Close();
sw.Close();
File.Delete("file1.txt");
File.Move("file2.txt", "file1.txt");