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 file name, with the specified character encoding, byte order mark detection option, and buffer size.

public StreamReader (string path, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)

Parameters

path
A string that specifies the complete file path to read.
encoding
A System.Text.Encoding that specifies the character encoding to use.
detectEncodingFromByteOrderMarks
A bool value that indicates whether the new System.IO.StreamReaderis 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 .
bufferSize
A int that specifies the minimum buffer size, in number of 16-bit characters. If less than the minimum allowable size (128 characters), the minimum allowable size is used.

Exceptions

TypeReason
System.IO.IOExceptionpath is in an invalid format or contains invalid characters.
System.IO.DirectoryNotFoundExceptionThe directory information specified in path was not found.
System.IO.FileNotFoundExceptionThe file specified in path was not found.
ArgumentExceptionpath is an empty string ("").
ArgumentNullExceptionpath or encoding is null.
ArgumentOutOfRangeExceptionbuffersize is less than or equal to zero.

Remarks

This constructor initializes the StreamReader.CurrentEncoding property using encoding .

If requested, the current 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. See the System.Text.Encoding.GetPreamble method for more information.

Note:

path is not required to be a file stored on disk; it can be any part of a system that supports access via streams. For example, depending on the system, this class might be able to access a physical device.

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.

For information on the valid format and characters for path strings, see System.IO.Path.

Requirements

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