1

I am trying to write some text at the end of the file.

Here is my code

Dim Writer As System.IO.StreamWriter = IO.File.AppendText("D:\Vishal.txt")
Writer.WriteLine("I am Vishal")

But I am not getting anything in the above mentioned file. Also there are no errors in the program.

4

1 回答 1

5

您必须刷新流以将其写入缓冲区,您可以调用writer.Flushwriter.Close使用using-statement 什么是使用一次性对象时的最佳实践:

Using Writer As System.IO.StreamWriter = IO.File.AppendText("D:\Vishal.txt")
    Writer.WriteLine("I am Vishal")
End Using

之所以有效,是因为 aStreamWriter在处置之前就隐含地关闭了。

于 2013-04-26T22:56:21.230 回答