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 first published in June 2003
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close