Mega Code Archive

 
Categories / VB.Net / File Directory
 

Create StreamReader class for the specified stream

Imports System Imports System.IO Public Class Test     Public Shared Sub Main()         Dim path As String = "c:\temp\MyTest.txt"         Try             If File.Exists(path) Then                 File.Delete(path)             End If             Dim sw As StreamWriter = New StreamWriter(path)             sw.WriteLine("A")             sw.WriteLine("B")             sw.WriteLine("C")             sw.WriteLine("D")             sw.Close()             Dim fs As FileStream = New FileStream(path, FileMode.Open)             Dim sr As StreamReader = New StreamReader(fs)             Do While sr.Peek() >= 0                 Console.WriteLine(sr.ReadLine())             Loop             sr.Close()             fs.Close()         Catch e As Exception             Console.WriteLine("The process failed: {0}", e.ToString())         End Try     End Sub End Class