PART I
C h a p t e r 1 4 :
U s i n g I / O
383
PART IPART I
try {
Console.WriteLine("This is the start of the log file.");
for(int i=0; i<10; i++) Console.WriteLine(i);
Console.WriteLine("This is the end of the log file.");
} catch(IOException exc) {
Console.WriteLine("Error Writing Log File");
Console.WriteLine(exc.Message);
}
log_out.Close();
}
}
When you run this program, you won’t see any of the output on the screen, but the file
logfile.txt
will contain the following:
This is the start of the log file.
0
1
2
3
4
5
6
7
8
9
This is the end of the log file.
On your own, you might want to experiment with redirecting the other built-in streams.
Do'stlaringiz bilan baham: |