Mega Code Archive

 
Categories / VB.Net / File Directory
 

File ReadAllLines opens a text file, reads all lines of the file, and then closes 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             Dim createText() As String = {"Hello", "And", "Welcome"}             File.WriteAllLines(path, createText)         End If         Dim appendText As String = "This is extra text" + Environment.NewLine         File.AppendAllText(path, appendText)         Dim readText() As String = File.ReadAllLines(path)         Dim s As String         For Each s In readText             Console.WriteLine(s)         Next     End Sub End Class