|
-
Feb 16th, 2002, 11:26 PM
#1
Thread Starter
Lively Member
Reading from a text file.
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..
Last edited by Jes|er; Feb 16th, 2002 at 11:47 PM.
12/32/84 - I need some code to make me a sandwhich.
-
Feb 17th, 2002, 05:18 PM
#2
I just know that you have to do it with System.IO.StreamReader
I'm new to .NET (my second day ) so dont expect me to write the code, hehe
something like this:
Dim strReader as StreamReader = File.OpenText("myfile.txt")
and read a line with strReader.ReadLine()
-
Feb 17th, 2002, 05:24 PM
#3
actually here's the code that somehow looks like the code in my book 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|