Initializes a new instance of the FileStream object with the specified path, creation mode, read/write and sharing permission, and buffer size.
[Visual Basic] Overloads Public Sub New( _ ByVal path As String, _ ByVal mode As FileMode, _ ByVal access As FileAccess, _ ByVal share As FileShare, _ ByVal bufferSize As Integer, _ ByVal useAsync As Boolean _ ) [C#] public FileStream( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync ); [C++] public: FileStream( String* path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync ); [JScript] public function FileStream( path : String, mode : FileMode, access : FileAccess, share : FileShare, bufferSize : int, useAsync : Boolean );
Exception Type | Condition |
---|---|
ArgumentNullException | path is null. |
ArgumentException | path is an empty string. |
ArgumentOutOfRangeException | mode is not a field of FileMode. |
ArgumentOutOfRangeException | access is not a field of FileAccess. |
ArgumentOutOfRangeException | share is not a field of FileShare. |
ArgumentOutOfRangeException | bufferSize is not positive. |
FileNotFoundException | The file cannot be found. For example, the exception is thrown if mode is FileMode.Truncate, and the file specified by path does not exist. The file must already exist in this mode. In addition, this exception is also called if mode is FileMode.Open, and the file specified by path does not exist. The file must already exist in this mode. |
IOException | An I/O error occurs. For example, the exception is thrown if: path is not a valid path. That is, "c:\\Dir\myfile.txt" is missing an escape character in front of the backslash between Dir and myfile.txt.The directory path leading to the file specified by path does not exist on the system. That is, if Dir is not a directory on drive C, "c:\\Dir\\myfile.txt" will result in an error. mode is FileMode.CreateNew and the file specified by path already exists. The file must not already exist in this mode. access requested is not permitted by the operating system for the specified path. For example: access is read/write and there is an attempt to open the existing file "c:\\Dir\\myfile.txt", but the file or directory is set for read-only access. |
SecurityException | The caller does not have the appropriate FileIOPermission. |
NGWS Runtime Security:
FileIOPermissionAccess.Write | Required by FileMode.Create or FileMode.CreateNew.
Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not exist, or when access is FileAccess.Read. Required by FileMode.Truncate. Required by FileAccess.Write. Required by FileAccess.ReadWrite. |
FileIOPermissionAccess.Read | Required by FileMode.Open.
Required by FileAccess.Read. Required by FileAccess.ReadWrite. |
FileIOPermissionAccess.Append | Required by FileMode.Create or FileMode.CreateNew.
Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist. Required by FileMode.OpenOrCreate if the file does not yet exist. |
System.Security.Permissions.FileIOPermissionAccess.Append and System.Security.Permissions.FileIOPermissionAccess.Write | Required by FileMode.Create or FileMode.CreateNew.
Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist. Required by FileMode.OpenOrCreate if the file does not yet exist. |
FileIOPermissionAccess.Read | Required by FileMode.Open.
Required by FileAccess.Read. |
FileIOPermissionAccess.Write | Required by FileMode.OpenOrCreate if access is FileAccess.Read.
Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file already exists. Required by FileMode.Truncate. Required by FileAccess.Write. |
System.Security.Permissions.FileIOPermissionAccess.Read and System.Security.Permissions.FileIOPermissionAccess.Write | Required by FileAccess.ReadWrite. |
FileStream Class | FileStream Members | System.IO Namespace | FileStream Constructor Overload List