Constructs and initializes a new instance of the System.IO.FileStream class with the specified path and creation mode.
- 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.
Type Reason System.Security.Permissions.FileIOPermission Requires 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.
Type Reason ArgumentException path is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. ArgumentNullException path is null. System.Security.SecurityException The caller does not have the required permission. System.IO.FileNotFoundException mode is FileMode.Truncate or FileMode.Open, but the specified file cannot be found. If a different mode is specified and the file cannot be found, a new one is created. System.IO.IOException An I/O error occurred, such as specifying FileMode.CreateNew when the file specified by path already exists. System.IO.DirectoryNotFoundException The directory information specified in path does not exist. System.IO.PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length. ArgumentOutOfRangeException mode contains an invalid value.
This constructor sets FileAccess.ReadWrite access to the file, and the Stream.CanRead and Stream.CanWrite properties of the current instance are set to true .
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 specifies a device that does not support seeking, the FileStream.CanSeek property of the resulting System.IO.FileStream is required to be false.
Note: For additional information, see Stream.CanSeek .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.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0