Results 1 to 3 of 3

Thread: Reading from a text file.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    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.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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()

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    actually here's the code that somehow looks like the code in my book it works just fine

    VB Code:
    1. Imports System.IO
    2.  
    3. Module Module1
    4.  
    5.     Sub Main()
    6.         Try
    7.             Dim strReader As StreamReader = File.OpenText("c:\test.txt")
    8.             Dim strLine As String
    9.  
    10.             Do
    11.                 strLine = strReader.ReadLine()
    12.                 Console.WriteLine(strLine)
    13.             Loop While Nothing <> strLine
    14.  
    15.         Catch e As FileNotFoundException
    16.             Console.WriteLine(e.Message)
    17.         End Try
    18.  
    19.  
    20.         ' I dunno how to stop the console from closing, so I do this
    21.         Console.ReadLine()
    22.     End Sub
    23. 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
  •  



Click Here to Expand Forum to Full Width