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

System.IO.StreamWriter Constructor

Constructs and initializes a new instance of the System.IO.StreamWriter class for the specified file on the specified path, using the default encoding and buffer size.

public StreamWriter (string path)

Parameters

path
A string that specifies the complete file path to write to.

Permissions

TypeReason
System.Security.Permissions.FileIOPermissionRequires permission for reading and writing files. See System.Security.Permissions.FileIOPermissionAccess.Read, System.Security.Permissions.FileIOPermissionAccess.Write

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.
UnauthorizedAccessExceptionAccess to path is denied.
ArgumentExceptionpath is an empty string ("").
ArgumentNullExceptionpath is null.
System.Security.SecurityExceptionThe caller does not have the required permission.
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the implementation-specific maximum length.

Remarks

This constructor initializes the StreamWriter.Encoding property to a System.Text.UTF8Encoding whose System.Text.Encoding.GetPreamble method returns an empty byte array. For additional information, see TextWriter.Encoding .

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 .

The default buffer size can typically be around 4 KB.

Requirements

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