December 2001
Intermediate to advanced
416 pages
8h 16m
English
Let's assume that the user has entered a valid text file name for the program. Our job, then, is to open the file, read its contents, and after processing those contents, write the results out to a second file, which we need to create. Let's see how we do this.
Support for file input/output is encapsulated in the System.IO namespace. So the first thing we need to do is open the namespace to the compiler:
using System.IO;
Text files are read and written through the StreamReader and StreamWriter classes. There are various ways to create instances of these classes—for example,
string file_name = @"C:\fictions\gnome.txt"; StreamReader freader = File.OpenText( file_name ); StreamWriter fwriter = ...
Read now
Unlock full access