Reading a file using the IO library

The IO Class Library provides the functionality for all the input/output of an app. This example demonstrates how to read from a file using FileStream & StreamReader classes.

Please let other users know how useful this tip is by rating it below. And, submit your own .NET tip or code.


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 last published in June 2003

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close