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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.