Implements a System.IO.TextReader that reads characters from a byte stream in a particular encoding.
See Also: StreamReader Members
System.IO.StreamReader is designed for character input in a particular encoding, whereas the System.IO.Stream class is designed for byte input and output. Use System.IO.StreamReader for reading lines of information from a standard text file.
System.IO.StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system. If you get the current character encoding using the StreamReader.CurrentEncoding property, the value is not reliable until after the first StreamReader.Read method, since encoding auto detection is not done until the first call to a StreamReader.Read method.
The StreamReader.Read(Char, int, int) and StreamWriter.Write(Char, int, int) method overloads read and write the number of characters specified by the count parameter. These are to be distinguished from BufferedStream.Read(Byte, int, int) and BufferedStream.Write(Byte, int, int), which read and write the number of bytes specified by the count parameter. Use the System.IO.BufferedStream methods only for reading and writing an integral number of byte array elements.
When reading from a System.IO.Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.
For a list of common I/O tasks, see Common I/O Tasks.