I/O system
1. Basic Concepts
Data Stream: an abstraction that generates or uses information, including byte data streams and character data streams;
Byte data streams and character data streams: byte data streams can process ASCII character sets, but are not suitable for handling Unicode characters. character data streams can process the latter;
2. byte data streams)
System. IO. Stream: the Stream class represents the byte data Stream. It is an abstract class and is the base class of all other data Stream classes, including some common methods and attributes;
Http://msdn.microsoft.com/en-us/library/system.io.stream.aspx
Some specific byte data Stream classes are derived from the Stream class, such as BufferedStream, FileStream, MemoryStream, and UnmanagedMenoryStream)
3. character data stream
The TextReader and TextWrite classes represent character data streams. They are abstract classes and are the base classes of all other character data streams, including some common methods and attributes;
Http://msdn.microsoft.com/en-us/library/system.io.textreader.aspx
Http://msdn.microsoft.com/en-us/library/system.io.textwriter.aspx
Some data stream classes that implement the TextReader and TextWrite classes include StreamReader, StreamWriter, StringReader, and StringWriter)
4. Console I/O
The relationship between the console I/O and the character data stream class has not been clarified during the first reading, so I will repeat it again.
First, we will introduce the character data stream of the standard data stream), that is, Console. In, Console. Out, and Console. Error. You only need to know the standard data stream)
Secondly, we need to clarify the relationship between the Console. In data stream, Console class, And TextReader class.
Public staticTextReaderIn {get ;}
Console. in is a property of the Console class. This property can return the objects of the TextReader class. in data stream is an instance of the TextReader class ", Console. in. read () is actually calling the Read () method of TextReader, TextReader. read ).
PublicstaticintRead()
{
ReturnIn. Read ();
}
Then you need to understand the Console. the Read () method is Console. the code of the Read () method returns In. read (), then Console. read () is to call the Console first. the In attribute instantiates TextReader and then calls its Read () method, which is equivalent to the Console. in. read ().
The principles of other methods such as ReadLine () are the same.