The IO classes in the IO Class Library provide the basic functionality for all input/output functionality of an application -- reading or writing a file, accessing a directory, checking file access permissions, etc. This example demonstrates how to read from a file using the FileStream and StreamReader classes:
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
Class ReadFile
Shared Sub Main()
'Declare a file stream object
Dim o As
FileStream
'Declare a stream reader object
Dim r As
StreamReader
'Open the file
o = New FileStream("c:myfile.txt",
FileMode.Open,FileAccess.Read, FileShare.Read)
'Read the output in a stream reader
r = New StreamReader(o)
'Display the content of the file
msgbox(r.ReadtoEnd)
End Sub
End Class
This was first published in June 2003