简体   繁体   English

在vb.net中使用FileWriter

[英]Using FileWriter in vb.net

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. 程序中也没有错误。

You have to flush the stream to write it's buffer, you could call writer.Flush , writer.Close or use the using -statement what is best practise anyway when using disposable objects: 你必须刷新写它的缓冲区中的数据流,你可以调用writer.Flushwriter.Close或使用using语句来什么是最好的做法无论如何使用一次性对象时:

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

That works because a StreamWriter gets closed implicitely before it's disposed. 之所以行得通,是因为StreamWriter在处理之前隐式关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM