How would I go about reading data from a text file and
then outputing to the screen? Actually what I need is
to know how to make a call(?) to a certain line in a
text file, and then output that info to a console window..
Printable View
How would I go about reading data from a text file and
then outputing to the screen? Actually what I need is
to know how to make a call(?) to a certain line in a
text file, and then output that info to a console window..
I just know that you have to do it with System.IO.StreamReader
I'm new to .NET (my second day:D ) so dont expect me to write the code, hehe:p
something like this:
Dim strReader as StreamReader = File.OpenText("myfile.txt")
and read a line with strReader.ReadLine()
actually here's the code that somehow looks like the code in my book:D it works just fine
VB Code:
Imports System.IO Module Module1 Sub Main() Try Dim strReader As StreamReader = File.OpenText("c:\test.txt") Dim strLine As String Do strLine = strReader.ReadLine() Console.WriteLine(strLine) Loop While Nothing <> strLine Catch e As FileNotFoundException Console.WriteLine(e.Message) End Try ' I dunno how to stop the console from closing, so I do this Console.ReadLine() End Sub End Module