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 byte order mark detection option. [Edit]

public StreamReader (string path, bool detectEncodingFromByteOrderMarks)

Parameters

path
A string that specifies the complete file path to read. [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]

Exceptions

TypeReason
System.IO.IOExceptionpath is in an invalid format or contains invalid characters. [Edit]
System.IO.DirectoryNotFoundExceptionThe directory information specified in path was not found. [Edit]
System.IO.FileNotFoundExceptionThe file specified in path was not found. [Edit]
ArgumentExceptionpath is an empty string (""). [Edit]
ArgumentNullExceptionpath is null. [Edit]

Remarks

This constructor initializes the StreamReader.CurrentEncoding property to System.Text.UTF8Encoding , and the internal buffer to the default size.

Note: The default buffer size is implementation defined.

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, UTF-8 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.

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

[Edit]

Requirements

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