127
C#.net
51 {
52 Console.WriteLine("The input file #2 does not exist!");
53 FailureFlag = 1;
54 }
55 OutputFile.Close(); // Close the output file
56 if (FailureFlag == 0)
57 Console.WriteLine("Two files have been merged into output file!");
58 else
59 Console.WriteLine("The operation failed due to incorrect files!");
60 }
61 }
62 }
For file processing, the program needs to import the System.IO namespace, as
shown in line 5 of Listing5.7. Four classes are required for file processing in C#, as
shown in Listing5.7 and discussed next:
1. e StreamWriter (line 17) and StreamReader (line 26) classes rep-
resent the files for writing and reading, respectively. e WriteLine()
method of StreamWriter (lines 34 and 47) writes a line to the file. e
ReadLine()