Creates a new StreamReader for the given stream, with the specified character encoding and buffer size. This constructor automatically detects UTF-8, little endian Unicode, and big endian Unicode text.
[Visual Basic] Overloads Public Sub New( _ ByVal stream As Stream, _ ByVal encoding As Encoding, _ ByVal bufferSize As Integer, _ ByVal detectEncodingFromByteOrderMarks As Boolean _ ) [C#] public StreamReader( Stream stream, Encoding encoding, int bufferSize, bool detectEncodingFromByteOrderMarks ); [C++] public: StreamReader( Stream* stream, Encoding* encoding, int bufferSize, bool detectEncodingFromByteOrderMarks ); [JScript] public function StreamReader( stream : Stream, encoding : Encoding, bufferSize : int, detectEncodingFromByteOrderMarks : Boolean );
Exception Type | Condition |
---|---|
ArgumentException | The stream does not support reading. |
ArgumentNullException | stream or encoding is a null reference (in Visual Basic Nothing). |
ArgumentOutOfRangeException | bufferSize is negative. |
This constructor allows you to change the encoding the first time you read from the StreamReader. The detectEncodingFromByteOrderMarks parameter detects the encoding by looking at the first three bytes of the stream. It automatically recognizes UTF-8, little endian Unicode, and big endian Unicode text. If none of those three match, the user-provided Encoding is used.
StreamReader Class | StreamReader Members | System.IO Namespace | StreamReader Constructor Overload List