Asp.net PrependText而不是AppendText?
我正在使用下面的代码将一些文本写入文件。有没有一种方法可以代替使用AppendText来预处理写入文本文件的新数据?因此,不是将最新条目写入底部,而是将其写入文本文档的顶部Asp.net PrependText而不是AppendText?,asp.net,vb.net,Asp.net,Vb.net,我正在使用下面的代码将一些文本写入文件。有没有一种方法可以代替使用AppendText来预处理写入文本文件的新数据?因此,不是将最新条目写入底部,而是将其写入文本文档的顶部 Public filePath As String = "c:\path\log.txt" Public w As StreamWriter w = File.AppendText(filePath) w.WriteLine('Blah Blah') w.Flush() w.Close() 对于大
Public filePath As String = "c:\path\log.txt"
Public w As StreamWriter
w = File.AppendText(filePath)
w.WriteLine('Blah Blah')
w.Flush()
w.Close()
对于大多数常见的文件系统,不需要。您必须复制该文件。您可以通过这种方式对其进行预处理
Dim txtList As New List(Of String)
txtList.Add("top line of text")
Using sr As New StreamReader("c:\path\log.txt")
While Not sr.EndOfStream()
txtList.Add(sr.ReadLine)
End While
End Using
Using sw As New StreamWriter("c:\path\log.txt")
For Each line As String In txtList
sw.WriteLine(line)
Next
End Using