-api-id | -api-type |
---|---|
M:Windows.Storage.FileIO.WriteBufferAsync(Windows.Storage.IStorageFile,Windows.Storage.Streams.IBuffer) |
winrt method |
Writes data from a buffer to the specified file.
The file that the buffer of data is written to.
The buffer that contains the data to write.
No object or value is returned when this method completes.
The File Access sample shows you how to use WriteBufferAsync
to write data from a buffer to a file.
try
{
if (file != null)
{
IBuffer buffer = CryptographicBuffer.GenerateRandom(10);
await FileIO.WriteBufferAsync(file, buffer);
// Perform additional tasks after file is written
}
}
// 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 write.
Although the WriteBufferAsync
methods don't have a return value, you can still perform additional tasks after the text is written to the file, as the example shows.