Appending Text to a File in VB.NET

How to append text to a file in VB.NET?

Explanation

Appending Text to a File in VB.NET 2008

The functions StreamWriter Class and File.AppendText method is used to append text to an existing file.
Example:

Imports System.IO
Module Module1
Sub Main()
Dim w As StreamWriter
Dim r As StreamReader
w = File.AppendText("C:write.txt")
w.WriteLine("Appended Text")
w.Flush()
w.Close()
r = File.OpenText("c:write.txt")
Console.WriteLine(r.ReadToEnd)
Console.Read()
r.Close()
End Sub
End Module
Result:

Welcome to.Net Programming
This is an example to create, write to a File
Appended text

In the above example, the file 'write.txt' is appended with the text 'Appended Text' using the File.AppendText method. Appending text to your file is quite easy.

Visual Basic Tutorial


Ask Questions

Ask Question