FileAccess FileAccess FileAccess FileAccess Enum

定义

定义文件的读取、写入或读/写访问权限的常量。Defines constants for read, write, or read/write access to a file.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class FileAccess
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FileAccess
type FileAccess = 
Public Enum FileAccess
继承
属性

字段

Read Read Read Read 1

对文件的读访问。Read access to the file. 可从文件中读取数据。Data can be read from the file. Write 组合以进行读写访问。Combine with Write for read/write access.

ReadWrite ReadWrite ReadWrite ReadWrite 3

对文件的读写访问权限。Read and write access to the file. 可从文件读取数据和将数据写入文件。Data can be written to and read from the file.

Write Write Write Write 2

文件的写访问。Write access to the file. 可将数据写入文件。Data can be written to the file. Read 组合以进行读写访问。Combine with Read for read/write access.

示例

以下FileStream构造函数授予对现有文件的只读访问权限 (FileAccess.Read)。The following FileStream constructor grants read-only access to an existing file (FileAccess.Read).

FileStream^ s2 = gcnew FileStream( name, FileMode::Open, FileAccess::Read, FileShare::Read );
FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
Dim s2 As New FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read)

注解

创建文件和文本写入文件的示例,请参阅如何:向文件写入文本For an example of creating a file and writing text to a file, see How to: Write Text to a File. 从文件读取文本的示例,请参阅如何:从文件读取文本For an example of reading text from a file, see How to: Read Text from a File. 读取和写入二进制文件的示例,请参阅如何:对新创建的数据文件读取和写入For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.

一个FileAccess参数指定的构造函数的许多FileFileInfoFileStream,并具有对文件的其他构造函数是务必控制访问用户的类型。A FileAccess parameter is specified in many of the constructors for File, FileInfo, FileStream, and other constructors where it is important to control the kind of access users have to a file.

适用于

另请参阅