FileAccess 枚举


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

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

public enum class FileAccess
public enum FileAccess
public enum FileAccess
public enum FileAccess
type FileAccess = 
Public Enum FileAccess


Read 1

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

ReadWrite 3

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

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.

在许多构造函数中为 FileFileInfoFileStream和其他构造函数指定 FileAccess 参数,这对于控制用户对文件的访问类型很重要。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.