Steps to Use StreamReader
{"Image DocumentName": "Steps to Use StreamReader", "Image ImageDescription": "Execute a statement of the form. Dim readerVar As IO.StreamReader = _. IO.File.OpenText(filespec) or the pair of statements. Dim readerVar As IO.StreamReader. readerVar = IO.File.OpenText(filespec) Assume the file contains one item of data per line. Read items of data in order, one at a time, from the file with the ReadLine method. strVar = readerVar.ReadLine. After the desired items have been read from the file, terminate the communications link. readerVar.Close() 1. Execute a statement of the form. Dim readerVar As IO.StreamReader. A StreamReader is an object from the Input/Output class that can read a stream of. characters coming from a disk or coming over the Internet. The Dim statement. declares the variable readerVar to be of type StreamReader. 2. Execute a statement of the form. readerVar = IO.File.OpenText(filespec) where filespec identifies the file to be read. This statement establishes a communi-cations. link between the computer and the disk drive for reading data from the disk. Data then can be input from the specified file and assigned to variables in the pro-gram. This assignment statement is said to open the file for input. Just as with other variables, the declaration and assignment statements in Steps. 2 and 3 can be combined into the single statement. Dim readerVar As IO.StreamReader = IO.File.OpenText(filespec) 3. Read items of data in order, one at a time, from the file with the ReadLine method. Each datum is retrieved as a string. A statement of the form. strVar = readerVar.ReadLine. causes the program to look in the file for the next unread line of data and assign it. to the variable strVar. The data can be assigned to a numeric variable if it is first. converted to a numeric type with a statement such as. numVar = CDbl(readerVar.ReadLine) Note: If all the data in a file have been read by ReadLine statements and another item. is requested by a ReadLine statement, the item retrieved will have the value Nothing. 4. After the desired items have been read from the file, terminate the communications. link set in Step 3 with the statement. readerVar.Close() Chapter 3 - VB.NET by Schneider.", "Image XResolution": "37", "Image YResolution": "37", "Image ResolutionUnit": "Pixels/Centimeter", "Image Software": "SlidePlayer", "Image YCbCrPositioning": "Centered"}