Mega Code Archive

 
Categories / VB.Net / File Directory
 

FileInfo OpenText creates a StreamReader with UTF8 encoding that reads from an existing text file

Imports System Imports System.IO Imports System.Text Public Class OpenTextTest     Public Shared Sub Main()         Dim path As String = "c:\MyTest.txt"         Dim fi As New FileInfo(path)         If fi.Exists = false Then             Dim fs As FileStream = fi.Create()             Dim info() As Byte = New UTF8Encoding(true).GetBytes("This is some text in the file.")             fs.Write(info, 0, info.Length)             fs.Close()         End If         Dim sr As StreamReader = fi.OpenText()         Dim s As String = ""         While sr.EndOfStream = false             s = sr.ReadLine()             Console.WriteLine(s)         End While         sr.Close()     End Sub End Class