Mega Code Archive

 
Categories / VB.Net / File Directory
 

File AppendAllText appends string to the file, creating the file if it does not already exist

Imports System Imports System.IO Imports System.Text 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             Dim createText As String = "Hello and Welcome" + Environment.NewLine             File.WriteAllText(path, createText, Encoding.UTF8)         End If         Dim appendText As String = "This is extra text" + Environment.NewLine         File.AppendAllText(path, appendText, Encoding.UTF8)         Dim readText As String = File.ReadAllText(path)         Console.WriteLine(readText)     End Sub End Class