EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

FileIO.ReadBufferAsync | readBufferAsync method

Applies to Windows and Windows Phone

Reads the contents of the specified file and returns a buffer.

Syntax


public static IAsyncOperation<IBuffer> ReadBufferAsync(
  IStorageFile file
)

Parameters

file

Type: IStorageFile

The file to read.

Return value

Type: IAsyncOperation<IBuffer>

When this method completes, it returns an object (type IBuffer) that represents the contents of the file.

Examples

The File Access sample shows you how to use writeTextAsync(file, contents) to write text to a file, like this:



try
{
    if (file != null)
    {
        IBuffer buffer = await FileIO.ReadBufferAsync(file);

        // Use a dataReader object to read from the buffer
        using (DataReader dataReader = DataReader.FromBuffer(buffer))
        {
            string fileContent = dataReader.ReadString(buffer.Length);
            // Perform additional tasks
        }
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

In the example, file is a local variable that contains a storageFile that represents the file to read.

After readTextAsync completes, the buffer variable gets the contents of the file as an IBuffer object. You can then read from the buffer using a dataReader object and process the file contents as appropriate (as shown in the example.)

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

FileIO

 

 

Mostrar:
© 2014 Microsoft