StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. Use StreamReader for reading lines of information from a standard text file.
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.
By default, a StreamReader is not thread safe. See TextReader..::.Synchronized for a thread-safe wrapper.
The Read(array<Char>[]()[], Int32, Int32) and Write(array<Char>[]()[], Int32, Int32) method overloads read and write the number of characters specified by the count parameter. These are to be distinguished from BufferedStream..::.Read and BufferedStream..::.Write, which read and write the number of bytes specified by the count parameter. Use the BufferedStream methods only for reading and writing an integral number of byte array elements.
Note: |
|---|
When reading from a
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.