FileAccess 列舉


定義檔案讀取、寫入或讀取/寫入存取的常數。Defines constants for read, write, or read/write access to a file.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

public enum class 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.

File FileInfo在、 、FileStream和的許多函式中, 會指定參數,這些是控制使用者對檔案的存取類型很重要的其他函數。FileAccessA 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.