Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Dim fs As FileStream
' Delete the file if it exists.
If File.Exists(path) = False Then
' Create the file.
fs = File.Create(path)
Dim info As Byte() = _
New UTF8Encoding(True).GetBytes("This is some text in the file.")
' Add some information to the file.
fs.Write(info, 0, info.Length)
fs.Close()
End If
' Open the stream and read it back.
Dim sr As StreamReader = File.OpenText(path)
Do While sr.Peek() >= 0
Console.WriteLine(sr.ReadLine())
Loop
Dim input As TextReader = File.OpenText("MyFile.txt")
Dim line As String
line = input.ReadLine()
While Not (line Is Nothing)
ListBox1.Items.Add(line)
line = input.ReadLine()
End While
input.Close()