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

System.IO.FileStream Constructor

Constructs and initializes a new instance of the System.IO.FileStream class with the specified path, creation mode, and access type.

public FileStream (string path, FileMode mode, FileAccess access)

Parameters

path
A string containing the relative or absolute path for the file that the current System.IO.FileStream object will encapsulate.
mode
A System.IO.FileMode value that determines how to open or create the file.
access
A System.IO.FileAccess value that determines how the file can be accessed by the System.IO.FileStream object. This parameter is used to specify the initial values of the FileStream.CanRead and FileStream.CanWrite properties.

Permissions

TypeReason
System.Security.Permissions.FileIOPermissionRequires permission to read, write, and append to files. See System.Security.Permissions.FileIOPermissionAccess.Read, System.Security.Permissions.FileIOPermissionAccess.Write, and System.Security.Permissions.FileIOPermissionAccess.Append.

Exceptions

TypeReason
ArgumentNullExceptionpath is null.
ArgumentException

path is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

-or-

access specified Read and mode specified Create , CreateNew , Truncate or Append.

System.IO.FileNotFoundExceptionmode is FileMode.Truncate or FileMode.Open , but the specified file was not found. If a different mode is specified and the file was not found, a new one is created.
System.IO.IOExceptionAn I/O error occurred, such as specifying FileMode.CreateNew when the file specified by path already exists.
System.Security.SecurityExceptionThe caller does not have the required permission.
System.IO.DirectoryNotFoundExceptionThe directory information specified by path does not exist.
UnauthorizedAccessExceptionpath specified a read-only file and access is not Read , or path specified a directory.
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the system-defined maximum length.
ArgumentOutOfRangeExceptionmode or access contain an invalid value.

Remarks

This constructor sets read/write access to the file. Requests to open the file for writing by the current or another thread will fail until the System.IO.FileStream object has been closed. Read attempts will succeed.

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.

Stream.CanSeek is true for all System.IO.FileStream objects that encapsulate files. If path indicates a device that does not support seeking, the FileStream.CanSeek property on the resulting System.IO.FileStream is required to be false. For additional information, see Stream.CanSeek .

Requirements

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