FileMode Sabit listesi

Tanım

İşletim sisteminin bir dosyayı nasıl açması gerektiğini belirtir.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
Devralma
FileMode
Öznitelikler

Alanlar

Append 6

Varsa dosyayı açar ve dosyanın sonuna kadar arar veya yeni bir dosya oluşturur.Opens the file if it exists and seeks to the end of the file, or creates a new file. Bunun için Append izin gerekir.This requires Append permission. FileMode.Append , ile birlikte kullanılabilir FileAccess.Write .FileMode.Append can be used only in conjunction with FileAccess.Write. Dosyanın sonundan önce bir konuma aranmaya çalışmak bir IOException özel durum oluşturmadan, okuma girişimleri başarısız olur ve bir NotSupportedException özel durum oluşturur.Trying to seek to a position before the end of the file throws an IOException exception, and any attempt to read fails and throws a NotSupportedException exception.

Create 2

İşletim sisteminin yeni bir dosya oluşturması gerektiğini belirtir.Specifies that the operating system should create a new file. Dosya zaten varsa üzerine yazılır.If the file already exists, it will be overwritten. Bunun için Write izin gerekir.This requires Write permission. FileMode.Create dosya mevcut değilse, öğesini kullanın CreateNew ; Aksi takdirde, kullanın Truncate .FileMode.Create is equivalent to requesting that if the file does not exist, use CreateNew; otherwise, use Truncate. Dosya zaten varsa ancak gizli bir dosya ise, bir UnauthorizedAccessException özel durum oluşturulur.If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown.

CreateNew 1

İşletim sisteminin yeni bir dosya oluşturması gerektiğini belirtir.Specifies that the operating system should create a new file. Bunun için Write izin gerekir.This requires Write permission. Dosya zaten varsa, bir IOException özel durum oluşturulur.If the file already exists, an IOException exception is thrown.

Open 3

İşletim sisteminin var olan bir dosyayı açması gerektiğini belirtir.Specifies that the operating system should open an existing file. Dosyayı açma özelliği, numaralandırma tarafından belirtilen değere bağımlıdır FileAccess .The ability to open the file is dependent on the value specified by the FileAccess enumeration. FileNotFoundExceptionDosya yoksa bir özel durum oluşturulur.A FileNotFoundException exception is thrown if the file does not exist.

OpenOrCreate 4

Varsa, işletim sisteminin bir dosyayı açması gerektiğini belirtir; Aksi takdirde, yeni bir dosya oluşturulmalıdır.Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. Dosya ile açılırsa FileAccess.Read , Read izin gerekir.If the file is opened with FileAccess.Read, Read permission is required. Dosya erişimi ise FileAccess.Write , Write izin gerekir.If the file access is FileAccess.Write, Write permission is required. Dosya ile açılırsa FileAccess.ReadWrite , hem hem de Read Write izinleri gereklidir.If the file is opened with FileAccess.ReadWrite, both Read and Write permissions are required.

Truncate 5

İşletim sisteminin var olan bir dosyayı açması gerektiğini belirtir.Specifies that the operating system should open an existing file. Dosya açıldığında, boyutu sıfır bayt olacak şekilde kesilmelidir.When the file is opened, it should be truncated so that its size is zero bytes. Bunun için Write izin gerekir.This requires Write permission. Bir FileMode.Truncate özel duruma neden olan açılan dosyadan okuma girişimleri ArgumentException .Attempts to read from a file opened with FileMode.Truncate cause an ArgumentException exception.

Örnekler

Aşağıdaki FileStream Oluşturucu var olan bir dosyayı ( FileMode.Open ) açar.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)

Açıklamalar

Dosya oluşturma ve dosyaya metin yazma hakkında bir örnek için bkz. nasıl yapılır: bir dosyaya metin yazma.For an example of creating a file and writing text to a file, see How to: Write Text to a File. Dosyadan metin okuma hakkında bir örnek için bkz. nasıl yapılır: dosyadan metin okuma.For an example of reading text from a file, see How to: Read Text from a File. Bir ikili dosyaya okuma ve yazma örneği için bkz. nasıl yapılır: okuma ve yeni oluşturulan bir veri dosyasını yazma.For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.

Bir FileMode parametre,, ve için FileStream IsolatedStorageFileStream Open File ve yöntemlerinde FileInfo bir dosyanın nasıl açıldığını denetlemek için ve yöntemleri içinde belirtilir.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 Parametreler, bir dosyanın üzerine yazılıp yazılmayacağını, oluşturulduğunu, açıldığını veya bir birleşiminin olduğunu denetler.FileMode parameters control whether a file is overwritten, created, opened, or some combination thereof. OpenVar olan bir dosyayı açmak için kullanın.Use Open to open an existing file. Bir dosyaya eklemek için kullanın Append .To append to a file, use Append. Dosya kesmek veya yoksa bir dosya oluşturmak için kullanın Create .To truncate a file or create a file if it doesn't exist, use Create.

Şunlara uygulanır

Ayrıca bkz.