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
- 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. |
| 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. |
| 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 |
| 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 |
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é
- Open(String, FileMode)
- Open(FileMode)
- FileStream
- IsolatedStorageFileStream
- I/O souborů a proudůFile and Stream I/O
- Postupy: Čtení textu ze souboruHow to: Read Text from a File
- Postupy: Zápis textu do souboruHow to: Write Text to a File
- Postupy: Čtení a zápis do nově vytvořeného datového souboruHow to: Read and Write to a Newly Created Data File