FileMode 列挙型
定義
オペレーティング システムがファイルを開く方法を指定します。Specifies how the operating system should open a file.
public enum class FileMode
public enum FileMode
[System.Serializable]
public enum FileMode
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FileMode
type FileMode =
[<System.Serializable>]
type FileMode =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FileMode =
Public Enum FileMode
- 継承
- 属性
フィールド
Append | 6 | ファイルが存在する場合はそのファイルを開き、ファイルの末尾をシークします。存在しない場合は新しいファイルを作成します。Opens the file if it exists and seeks to the end of the file, or creates a new file. これには Append 許可が必要です。This requires Append permission. |
Create | 2 | オペレーティング システムが新しいファイルを作成することを指定します。Specifies that the operating system should create a new file. ファイルが既に存在する場合は上書きされます。If the file already exists, it will be overwritten. これには Write 許可が必要です。This requires Write permission. |
CreateNew | 1 | オペレーティング システムが新しいファイルを作成することを指定します。Specifies that the operating system should create a new file. これには Write 許可が必要です。This requires Write permission. ファイルが既に存在する場合は IOException 例外がスローされます。If the file already exists, an IOException exception is thrown. |
Open | 3 | オペレーティング システムが既存のファイルを開くことを指定します。Specifies that the operating system should open an existing file. ファイルを開けるかどうかは、FileAccess 列挙体で指定される値によって異なります。The ability to open the file is dependent on the value specified by the FileAccess enumeration. ファイルが存在しない場合は、FileNotFoundException 例外がスローされます。A FileNotFoundException exception is thrown if the file does not exist. |
OpenOrCreate | 4 | ファイルが存在する場合はオペレーティング システムがそのファイルを開き、存在しない場合は新しいファイルを作成することを指定します。Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. ファイルを |
Truncate | 5 | オペレーティング システムが既存のファイルを開くことを指定します。Specifies that the operating system should open an existing file. ファイルは、開かれると、サイズが 0 バイトになるように切り詰められます。When the file is opened, it should be truncated so that its size is zero bytes. これには Write 許可が必要です。This requires Write permission. |
例
次の FileStream
コンストラクターは、既存のファイル () を開き FileMode.Open
ます。The following FileStream
constructor opens an existing file (FileMode.Open
).
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.
FileMode
パラメーターは FileStream 、、、およびのメソッド内の、、およびのコンストラクターの多くで、 IsolatedStorageFileStream ファイルの Open
File FileInfo オープン方法を制御するために指定されます。A FileMode
parameter is specified in many of the constructors for FileStream, IsolatedStorageFileStream, and in the Open
methods of File and FileInfo to control how a file is opened.
FileMode
パラメーターは、ファイルを上書きするか、作成するか、開くか、またはその組み合わせを行うかを制御します。FileMode
parameters control whether a file is overwritten, created, opened, or some combination thereof. Open
既存のファイルを開くには、を使用します。Use Open
to open an existing file. ファイルに追加するには、を使用 Append
します。To append to a file, use Append
. ファイルを切り捨てる、またはファイルが存在しない場合は作成するには、を使用 Create
します。To truncate a file or create a file if it doesn't exist, use Create
.