FileOptions Enumeração
Definição
Representa opções avançadas para criação de um objeto FileStream.Represents advanced options for creating a FileStream object.
Esta enumeração tem um atributo FlagsAttribute que permite uma combinação bit a bit dos valores membros dela.
public enum class FileOptions
[System.Flags]
public enum FileOptions
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FileOptions
[<System.Flags>]
type FileOptions =
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type FileOptions =
Public Enum FileOptions
- Herança
- Atributos
Campos
| Asynchronous | 1073741824 | Indica que um arquivo pode ser usado para leitura e gravação assíncronas.Indicates that a file can be used for asynchronous reading and writing. |
| DeleteOnClose | 67108864 | Indica que um arquivo é excluído automaticamente quando ele não estiver mais em uso.Indicates that a file is automatically deleted when it is no longer in use. |
| Encrypted | 16384 | Indica que um arquivo é criptografado e pode ser descriptografado somente usando a mesma conta de usuário usada para criptografia.Indicates that a file is encrypted and can be decrypted only by using the same user account used for encryption. |
| None | 0 | Indica que nenhuma opção adicional deve ser usada ao criar um objeto FileStream.Indicates that no additional options should be used when creating a FileStream object. |
| RandomAccess | 268435456 | Indica que o arquivo é acessado aleatoriamente.Indicates that the file is accessed randomly. O sistema pode usar isso como uma dica para otimizar o cache de arquivo.The system can use this as a hint to optimize file caching. |
| SequentialScan | 134217728 | Indica que o arquivo deve ser acessado sequencialmente do começo ao fim.Indicates that the file is to be accessed sequentially from beginning to end. O sistema pode usar isso como uma dica para otimizar o cache de arquivo.The system can use this as a hint to optimize file caching. Se um aplicativo move o ponteiro do arquivo para acesso aleatório, poderá não ocorrer cache ideal; no entanto, a operação correta ainda é garantida.If an application moves the file pointer for random access, optimum caching may not occur; however, correct operation is still guaranteed. Especificar esse sinalizador pode aumentar o desempenho em alguns casos.Specifying this flag can increase performance in some cases. |
| WriteThrough | -2147483648 | Indica que o sistema deve gravar por meio de qualquer cache intermediário e ir diretamente para o disco.Indicates that the system should write through any intermediate cache and go directly to disk. |
Exemplos
O exemplo a seguir mostra como usar o valor assíncrono ao criar um fluxo de arquivo.The following example shows how to use the Asynchronous value when creating a file stream.
using System;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
WriteToFile();
}
static async void WriteToFile()
{
byte[] bytesToWrite = Encoding.Unicode.GetBytes("example text to write");
using (FileStream createdFile = File.Create("c:/Temp/testfile.txt", 4096, FileOptions.Asynchronous))
{
await createdFile.WriteAsync(bytesToWrite, 0, bytesToWrite.Length);
}
}
}
}
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
WriteToFile()
End Sub
Async Sub WriteToFile()
Dim bytesToWrite = Encoding.Unicode.GetBytes("example text to write")
Using createdFile As FileStream = File.Create("c:/Temp/testfile.txt", 4096, FileOptions.Asynchronous)
Await createdFile.WriteAsync(bytesToWrite, 0, bytesToWrite.Length)
End Using
End Sub
End Module
Comentários
A especificação do FileOptions.SequentialScan sinalizador pode aumentar o desempenho de aplicativos que lêem arquivos grandes usando o acesso sequencial.Specifying the FileOptions.SequentialScan flag can increase performance for applications that read large files using sequential access. Os ganhos de desempenho podem ser ainda mais perceptíveis para aplicativos que lêem arquivos grandes principalmente em sequência, mas eventualmente ignoram intervalos pequenos de bytes.Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.