Mega Code Archive

 
Categories / VB.Net / File Directory
 

File AppendText Method Creates a StreamWriter and appends UTF-8 encoded text to the file

Imports System Imports System.IO Public Class Test     Public Shared Sub Main()         Dim path As String = "c:\temp\MyTest.txt"         Dim sw As StreamWriter         If File.Exists(path) = False Then             sw = File.CreateText(path)             sw.WriteLine("A")             sw.WriteLine("B")             sw.WriteLine("C")             sw.Flush()             sw.Close()         End If         sw = File.AppendText(path)         sw.WriteLine("D")         sw.WriteLine("E")         sw.WriteLine("F")         sw.Flush()         sw.Close()         Dim sr As StreamReader = File.OpenText(path)         Dim s As String         Do While sr.Peek() >= 0             s = sr.ReadLine()             Console.WriteLine(s)         Loop         sr.Close()     End Sub End Class