FileMode Enumeración
Definición
Especifica cómo el sistema operativo debe abrir un archivo.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
- Herencia
- Atributos
Campos
| Append | 6 | Abre el archivo si existe y realiza una búsqueda hasta el final del mismo, o crea un archivo nuevo.Opens the file if it exists and seeks to the end of the file, or creates a new file. Requiere el permiso Append.This requires Append permission. |
| Create | 2 | Especifica que el sistema operativo debe crear un archivo nuevo.Specifies that the operating system should create a new file. Si el archivo ya existe, se sobrescribirá.If the file already exists, it will be overwritten. Requiere el permiso Write.This requires Write permission. |
| CreateNew | 1 | Especifica que el sistema operativo debe crear un archivo nuevo.Specifies that the operating system should create a new file. Requiere el permiso Write.This requires Write permission. Si el archivo ya existe, se produce una excepción IOException.If the file already exists, an IOException exception is thrown. |
| Open | 3 | Especifica que el sistema operativo debe abrir un archivo existente.Specifies that the operating system should open an existing file. La capacidad de abrir el archivo depende del valor especificado por la enumeración FileAccess.The ability to open the file is dependent on the value specified by the FileAccess enumeration. Se desencadena una excepción FileNotFoundException si el archivo no existe.A FileNotFoundException exception is thrown if the file does not exist. |
| OpenOrCreate | 4 | Especifica que el sistema operativo debe abrir un archivo si ya existe; en caso contrario, debe crearse uno nuevo.Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. Si se abre el archivo con |
| Truncate | 5 | Especifica que el sistema operativo debe abrir un archivo existente.Specifies that the operating system should open an existing file. Cuando se abre el archivo, debe truncarse el archivo para que su tamaño sea de cero bytes.When the file is opened, it should be truncated so that its size is zero bytes. Requiere el permiso Write.This requires Write permission. Al intentar leer un archivo abierto con |
Ejemplos
El siguiente FileStream constructor abre un archivo existente ( 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)
Comentarios
Para obtener un ejemplo de cómo crear un archivo y escribir texto en un archivo, vea Cómo: escribir texto en un archivo.For an example of creating a file and writing text to a file, see How to: Write Text to a File. Para obtener un ejemplo de cómo leer texto de un archivo, consulte Cómo: leer texto de un archivo.For an example of reading text from a file, see How to: Read Text from a File. Para obtener un ejemplo de cómo leer y escribir en un archivo binario, vea Cómo: leer y escribir en un archivo de datos recién creado.For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.
Un FileMode parámetro se especifica en muchos de los constructores de FileStream , IsolatedStorageFileStream y en los Open métodos de File y FileInfo para controlar cómo se abre un archivo.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 los parámetros controlan si un archivo se sobrescribe, se crea, se abre o alguna combinación de ambos.FileMode parameters control whether a file is overwritten, created, opened, or some combination thereof. OpenSe usa para abrir un archivo existente.Use Open to open an existing file. Para anexar a un archivo, use Append .To append to a file, use Append. Para truncar un archivo o crear un archivo si no existe, use Create .To truncate a file or create a file if it doesn't exist, use Create.
Se aplica a
Consulte también
- Open(String, FileMode)
- Open(FileMode)
- FileStream
- IsolatedStorageFileStream
- E/S de archivos y secuenciasFile and Stream I/O
- Procedimiento para leer texto de un archivoHow to: Read Text from a File
- Procedimiento para escribir texto en un archivoHow to: Write Text to a File
- Procedimiento para leer y escribir en un archivo de datos recién creadoHow to: Read and Write to a Newly Created Data File