Creates a new instance of the StreamReader class on the specified path, 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 path As String, _ ByVal encoding As Encoding, _ ByVal bufferSize As Integer, _ ByVal detectEncodingFromByteOrderMarks As Boolean _ ) [C#] public StreamReader( string path, Encoding encoding, int bufferSize, bool detectEncodingFromByteOrderMarks ); [C++] public: StreamReader( String* path, Encoding* encoding, int bufferSize, bool detectEncodingFromByteOrderMarks ); [JScript] public function StreamReader( path : String, encoding : Encoding, bufferSize : int, detectEncodingFromByteOrderMarks : Boolean );
Exception Type | Condition |
---|---|
ArgumentException | path is an empty string (""). |
ArgumentNullException | path 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