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)

備註

如需建立檔案,並將文字寫入至檔案的範例,請參閱How to:將文字寫入至檔案For an example of creating a file and writing text to a file, see How to: Write Text to a File. 從檔案讀取文字的範例,請參閱How to:從檔案讀取文字For an example of reading text from a file, see How to: Read Text from a File. 如需讀取和寫入二進位檔案的範例,請參閱How to:讀取和寫入至新建立的資料檔案For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.

AFileAccess參數指定於許多建構函式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.

適用於

另請參閱