class Redirect {
static void Main() {
StreamWriter log_out = null;
try {
log_out = new StreamWriter("logfile.txt");
// logfile.txt.
Console.SetOut(log_out);
Console.WriteLine(" .");
for(int i=0; i<10; i++) Console.WriteLine(i);
Console.WriteLine(" .");
} catch(IOException exc) {
Console.WriteLine(" -\" + exc.Message);
} finally {
if(log_out!= null) log_out.Close();
}
}
}
, logfile. txt .
.
.
.
. ( ) . , , int, double short. C# BinaryReader nBinaryWriter. , , , .
BinaryWri ter
BinaryWriter , , . :
BinaryWriter(Stream output)
output , . output , FileStream. output , ArgumentNullException. , output, , ArgumentException. BinaryWriter . .
BinaryWriter , C# . . 14.5. , string . , BinaryWriter Close() Flush (), .
14.5. , BinaryWriter
Void
Write
(sbyte value)
sbyte
Void
Write
(byte value)
byte
Void
|
|
Write
(byte[] buffer)
byte
Void
Write
(short value)
short ( )
Void
Write
(ushort value)
ushort ( )
Void
Write
(int value)
int
Void
Write
(uint value)
uint ( )
Void
Write
(long value)
long ( )
Void
Write
(ulong value)
ulong ( )
Void
Write
(float value)
float ( )
Void
Write
(double value)
double ( )
Void
Write
(decimal value)
decimal ( )
Void
Write
(char ch)
Void
Write
(char[] buffer)
Void
Write
(string value)
string, -
BinaryReader , , . :
BinaryReader(Stream input)
input , . input , FileStream. , input, , ArgumentException. BinaryReader . .
BinaryReader , C# . . 14.6. , , , Readstring () , . IOException, . , .
14.6. , BinaryReader
Bool ReadBoolean ()
bool
Byte ReadByteO
byte
Sbyte ReadSByteO
sbyte
byte[] ReadBytes(int count)
|
|
count
Char ReadCharO
char
char[] ReadChars(int count)
count
Decimal ReadDecimal()
decimal
Double ReadDoubleO
double
Float ReadSingleO
float
Short Readlntl6()
short
Int Readlnt32()
int
Long Readlnt64()
long
Ushort ReadUIntl6()
ushort
Uint ReadUInt32()
uint
Ulong ReadUInt64()
ulong
String ReadStringO
string, . , BinaryWriter
BinaryWriter Read ().