FileAccess 枚举

定义

定义文件的读取、写入或读/写访问权限的常量。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
继承
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.

FileAccess File、、和其他构造函数的许多构造函数FileInfoFileStream都指定了一个参数, 该参数对于控制用户对文件的访问类型很重要。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.

适用于

另请参阅