StreamReader Class

Implements a TextReader that reads characters from a byte stream in a particular encoding.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

Syntax

public class StreamReader

Remarks

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 (Char[], Int32, Int32) and Write(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.

Version Information

Available in .NET Micro Framework version 3.0 and above.

See Also

Reference

StreamReader Members
System.IO Namespace