Mono Class Library: System.IO.StreamReader Overview | Members

System.IO.StreamReader Constructor

Constructs and initializes a new instance of the System.IO.StreamReader class for the specified stream, with the specified character encoding, byte order mark detection option, and buffer size. [Edit]

public StreamReader (Stream stream, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)

Parameters

stream
The System.IO.Stream to read. [Edit]
encoding
A System.Text.Encoding that specifies the character encoding to use. [Edit]
detectEncodingFromByteOrderMarks
A bool value that indicates whether the new System.IO.StreamReader is required to look for byte order marks at the beginning of the stream. Specify true to enable detection of byte order marks; otherwise, specify false . [Edit]
bufferSize
A int that specifies the minimum buffer size, in number of 16-bit characters. If bufferSize is less than the minimum allowable size (128 characters), the minimum allowable size is used. [Edit]

Exceptions

TypeReason
ArgumentExceptionstream does not support reading. [Edit]
ArgumentNullExceptionstream or encoding is null. [Edit]
ArgumentOutOfRangeExceptionbufferSize is less than or equal to zero. [Edit]

Remarks

This constructor initializes the StreamReader.CurrentEncoding property using encoding parameter the StreamReader.BaseStream property using stream .

If requested, this constructor detects the encoding by examining the first three bytes of the stream. The constructor automatically recognizes UTF-8, little-endian Unicode, and big-endian Unicode text if the file starts with the appropriate byte order marks. Otherwise, the user-provided encoding is used. For more information, see the System.Text.Encoding.GetPreamble method.

Note: 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.

[Edit]

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0