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 _ ) [C#] public FileStream( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize ); [C++] public: FileStream( String* path, FileMode mode, FileAccess access, FileShare share, int bufferSize ); [JScript] public function FileStream( path : String, mode : FileMode, access : FileAccess, share : FileShare, bufferSize : int );
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 flag required by FileMode.Create or FileMode.CreateNew, by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not exist, or when access is FileAccess.Read, and by FileMode.Truncate, FileAccess.Write, and FileAccess.ReadWrite. |
FileIOPermissionAccess | Read flag required by FileMode.Open, FileAccess.Read, and FileAccess.ReadWrite. |
FileIOPermissionAccess | Append flag required by FileMode.Create or FileMode.CreateNew, by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist, and byFileMode.OpenOrCreate if the file does not yet exist. |
FileStream Class | FileStream Members | System.IO Namespace | FileStream Constructor Overload List