FileMode Výčet

Definice

Určuje, jak má operační systém otevřít soubor.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
Dědičnost
FileMode
Atributy

Pole

Append 6

Otevře soubor, pokud existuje, a hledá na konci souboru nebo vytvoří nový soubor.Opens the file if it exists and seeks to the end of the file, or creates a new file. To vyžaduje Append oprávnění.This requires Append permission. FileMode.Append dá se použít jenom ve spojení s FileAccess.Write .FileMode.Append can be used only in conjunction with FileAccess.Write. Pokus o vyhledání pozice před koncem souboru vyvolá IOException výjimku a jakýkoliv pokus o čtení se nezdaří a vyvolá NotSupportedException výjimku.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

Určuje, že by měl operační systém vytvořit nový soubor.Specifies that the operating system should create a new file. Pokud už soubor existuje, přepíše se.If the file already exists, it will be overwritten. To vyžaduje Write oprávnění.This requires Write permission. FileMode.Create je ekvivalentem k tomu, že pokud soubor neexistuje, použijte CreateNew ; jinak použijte Truncate .FileMode.Create is equivalent to requesting that if the file does not exist, use CreateNew; otherwise, use Truncate. Pokud soubor již existuje, ale je to skrytý soubor, UnauthorizedAccessException je vyvolána výjimka.If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown.

CreateNew 1

Určuje, že by měl operační systém vytvořit nový soubor.Specifies that the operating system should create a new file. To vyžaduje Write oprávnění.This requires Write permission. Pokud soubor již existuje, IOException je vyvolána výjimka.If the file already exists, an IOException exception is thrown.

Open 3

Určuje, že by měl operační systém otevřít existující soubor.Specifies that the operating system should open an existing file. Možnost otevření souboru závisí na hodnotě určené FileAccess výčtem.The ability to open the file is dependent on the value specified by the FileAccess enumeration. FileNotFoundExceptionPokud soubor neexistuje, je vyvolána výjimka.A FileNotFoundException exception is thrown if the file does not exist.

OpenOrCreate 4

Určuje, že má operační systém otevřít soubor, pokud existuje. v opačném případě by se měl vytvořit nový soubor.Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. Pokud je soubor otevřený v FileAccess.Read , Read vyžaduje se oprávnění.If the file is opened with FileAccess.Read, Read permission is required. Pokud přístup k souboru je FileAccess.Write , Write vyžaduje se oprávnění.If the file access is FileAccess.Write, Write permission is required. Pokud je soubor otevřen s nástrojem FileAccess.ReadWrite , Read Write jsou vyžadována obě oprávnění a.If the file is opened with FileAccess.ReadWrite, both Read and Write permissions are required.

Truncate 5

Určuje, že by měl operační systém otevřít existující soubor.Specifies that the operating system should open an existing file. Když je soubor otevřený, měl by být oříznutý tak, aby jeho velikost byla nula bajtů.When the file is opened, it should be truncated so that its size is zero bytes. To vyžaduje Write oprávnění.This requires Write permission. Pokusy o čtení ze souboru otevřeného s FileMode.Truncate příčinou ArgumentException výjimky.Attempts to read from a file opened with FileMode.Truncate cause an ArgumentException exception.

Příklady

Následující FileStream konstruktor otevře existující soubor ( 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)

Poznámky

Příklad vytvoření souboru a zápis textu do souboru naleznete v tématu How to: Write text to a File.For an example of creating a file and writing text to a file, see How to: Write Text to a File. Příklad čtení textu ze souboru naleznete v tématu How to: Read text from a File.For an example of reading text from a file, see How to: Read Text from a File. Příklad čtení a zápisu do binárního souboru naleznete v tématu How to: Read and Write to a Write to a Write to a Write to a Write do nově vytvořeného datového souboru.For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.

FileModeParametr je zadán v mnoha konstruktorech pro FileStream , a IsolatedStorageFileStream v Open metodách File a FileInfo pro řízení způsobu, jakým je soubor otevřen.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 parametry určují, zda je soubor přepsán, vytvořen, otevřen nebo je nějaký jeho kombinace.FileMode parameters control whether a file is overwritten, created, opened, or some combination thereof. Použijte Open k otevření existujícího souboru.Use Open to open an existing file. Chcete-li se připojit k souboru, použijte Append .To append to a file, use Append. Chcete-li zkrátit soubor nebo vytvořit soubor, pokud neexistuje, použijte Create .To truncate a file or create a file if it doesn't exist, use Create.

Platí pro

Viz také