string lod = Application.StartupPath + "\\logs\\mongod.log";
FileInfo f = new FileInfo(lod);
FileStream fs = f.Open(FileMode.Open);
StreamReader sr = new StreamReader(fs);
string str = sr.ReadToEnd();
sr.Close();
str = str.Replace("C:\\Users\\DELL\\Ubiquiti UniFi", Application.StartupPath);
//更改保存文本
StreamWriter sw = new StreamWriter(lod,false);
sw.WriteLine(str);
sw.Close();

本文介绍了一种使用 C# 从指定路径读取 mongod.log 日志文件的方法,并展示了如何将读取的内容替换特定字符串后重新写回原文件的过程。
247

被折叠的 条评论
为什么被折叠?



