我必须在 vb .NET 中以编程方式删除文件的最后一个空行。有时,只有一个空行,有时是两个(但永远不会更多)。
我现在使用这些代码行:
fs = New FileStream(Fic_source, FileMode.Open, FileAccess.ReadWrite)
fs.Seek(-50, SeekOrigin.End)
Dim strEOF As String = New StreamReader(fs).ReadToEnd()
strEOF = strEOF .Replace(vbCrLf, "") '
strEOF = strEOF .Replace("\r", "") ' Removes every CR / LF / CRLF from the end of the file
strEOF = strEOF .Replace("\n", "") '
strEOF = String.Concat(strEOF , vbCrLf) ' adds an empty line to finish the file correctly
但我似乎无法弄清楚如何将我的流中的最后 50 个字符替换为 strEOF,有人知道吗?