我正在尝试将一些字符添加到现有文本文件的第一行,streamwriter.write 用我添加的字符长度覆盖该行是否有一种非常简单的方法来编写我想要的文本或我想要添加的字符不覆盖现有的,不使用流读取器或临时文件。我的代码:
FileStream fs = new FileStream(@"G:\PayLoad.txt",FileMode.Open);
StreamWriter sw = new StreamWriter(fs); \\ IF First line is ==>> 123456789
sw.BaseStream.Position = 0;
sw.Write("REM "); \\ This will overwrite to be ==>> REM 56789
sw.Close(); \\ we want it to be ==>> REM 123456789