1. Standard data streams are character data streams, so these streams are read-write characters
Console.Out standard output data stream
console.in standard input data stream
Console.error standard error data stream
2. All data flow classes are in the System.IO space----so you have to add using System.IO
stream represents byte data stream
Common methods:
void Close () closes the data stream void Flush () regardless of whether the buffer is full-built data is written to the physical device
int read (the byte array to be stored, the starting position of the read, the number of bytes read )------The number of bytes returned successfully------byte block
Read processing input The array is stored only temporarily <-------------
int ReadByte ()--------The integer representation of the successful return byte, and returns 1-------------------------a single byte at the end of the
void WriteByte (Byte b)--------writes a single byte to the output stream
void Write (the byte array written, the starting position of the write, the number of bytes written )-----------------------------block of bytes
Write processing output is written to an array that is only temporarily stored--------------->
The 3 derived classes of 3.Stream are: BufferedStream wraps byte data streams and buffers, buffering improves performance in many cases
FileStream byte data stream designed for file I/O
MemoryStream byte data streams that use memory to store
4.2 abstract classes of character data flow wrapper classes :
TextReader: Processing input textwriter processing output
TextReader Common methods:
void Close () to close the data source
int Read () returns the corresponding integer representation of the character, reaching the end of the return-1
int read (the byte array to be deposited, the starting position of the read, the number of bytes read)------The number of successful bytes returned
String ReadLine () reads a line of characters and returns it as a string, returning null at the end of the file
String ReadToEnd () reads all the remaining characters in the data stream and returns them as strings
TextWriter Common methods:
A single value----------------void Write (the value being written)-----can be an int val, double Val, bool Val, string Val, uint Val, char Val ....
Row value----------------void WriteLine ()
-----------------------virtual void close () to close the data flow
-----------------------virtual void Flush () allows data in the buffer to be written to the physical device
4.console.in Read console input (read from console)----------------------------It is an instance of TextReader
Normally used by the console provided by the method automatically read from the console.in
Console 2 Input methods: Read (returns the integer corresponding to the character)
Progressive buffer-------Press the ENTER key to read
And these characters are suspended in the input buffers until they are read
ReadLine (return string)
Always read characters until the ENTER key is pressed
5.console.out and Console.error (output to console) write to console output-----------------------is an instance of TextWriter (that is, an object)
2 methods:
Write ()
WriteLine ()
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
6.using System.IO-------------FileStream
Create a stream of bytes connected to a file: FileStream (file name-the full path to the files, how the file is manipulated )----default to FileAccess.ReadWrite
(constructor) FileStream ( filename-The full path of the file , How the file is manipulated, access rights )
access rights: FileAccess.Read FileAccess.Write FileAccess.ReadWrite
How the file works:
Filemode.append
FileMode.Create creates the output file, and if a file with the same name (or the file already exists) is deleted and then created
FileMode.CreateNew file cannot already exist
FileMode.Open
FileMode.OpenOrCreate exist just open not exist on create
Filemode.truncate opens an existing file but reduces its length to 0
Several exceptions: for the following reasons
FileNotFoundException file does not exist
IOException cannot open file due to I/O error
SecurityException user does not have access rights
DirectoryNotFoundException The specified directory is invalid
FileMode.
I/O for C #