A program that reads from a sequential access data file creates a FileStream object, and then the FileStream object is passed to a StreamReader object's constructor. Once this has been done, the ReadLine() method can be used to retrieve one line at a time from the data file. Show the sequence of instructions that would create the FileStream and StreamReader needed to access a data file, and then read one line from the file.
What will be an ideal response?
A program that reads from a sequential access data file contains many similar components to one that writes to a file. For example, a FileStream object is created, as in a program that writes to a file. However, the access must be FileAccess.Read (or ReadWrite), as in the following statement:
FileStream inFile =
new FileStream(FILENAME, FileMode.Open, FileAccess.Read);
Then, as when data is being written, the FileStream object is passed to a StreamReader object's constructor, as in the following statement:
StreamReader reader = new StreamReader(inFile);
After the StreamReader has been defined, the ReadLine() method can be used to retrieve one line at a time from the data file. For example, the following statement gets one line of data from the file and stores it in a string named recordIn:
string recordIn = reader.ReadLine();
You might also like to view...
A CAPTCHA is a series of letters and numbers that are distorted in some way
Indicate whether the statement is true or false
To print a mailing label, click ____ in the menu bar and then choose Labels to open the Labels dialog.
A. Envelopes B. AutoText C. Template D. Tools
You can format a macro button using 3-D effects by right-clicking the button, selecting ____ from the shortcut menu, then selecting the 3-D effects.
A. Shapes B. Format Shape C. Assign Shape D. Design Shape
You need to replace the CMOS battery in a laptop. Which of the following is a common location for the battery?
a. Under the DVD-ROM b. Behind the laptop battery c. Under the keyboard d. Behind the hard drive