Read stream one line at a time

  • Thread starter Thread starter Microsoft
  • Start date Start date
M

Microsoft

I am trying to use the openfilediaolog to open a file and read it one line
at a time.

openfiledialog returns a stream and from what I can see, streamreader is the
only way to read a file one line at a time

Anyone offer some guidance as to how to get around this.
 
Microsoft said:
I am trying to use the openfilediaolog to open a file and read it one line
at a time.

openfiledialog returns a stream and from what I can see, streamreader is
the
only way to read a file one line at a time

new StreamReader(dlg.OpenFile());

Niki
 
Hi,

This sample is from the MSDN documentation, shows hows to use the
StreamReader class to read a file line by line

The following example uses an instance of StreamReader to read text from
a file.
[Visual Basic]
Imports System
Imports System.IO

Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Back
Top