Mega Code Archive
File ReadAllLines opens a file, reads all lines of the file with the specified encoding, and then closes the file
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"}
File.WriteAllLines(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.ReadAllLines(path, Encoding.UTF8)
Dim s As String
For Each s In readText
Console.WriteLine(s)
Next
End Sub
End Class