0

Windows.Storage.FileIO.WriteBufferAsync方法,但WP8不支持。将缓冲区保存到手机上的存储文件的正确方法是什么?

4

1 回答 1

1

关于如何在此处继续,您有几个选择。但是,使您IBuffer更轻松地使用对象所需的扩展都位于System.Runtime.InteropServices.WindowsRuntime命名空间中。您可能还需要OpenStreamForWriteAsync扩展的System.IO命名空间。

private async void SaveBuffer(Windows.Storage.Streams.IBuffer myBuffer)
{
    Windows.Storage.StorageFile myFile = await Windows.Storage.StorageFile.GetFileFromPathAsync("...");

    using (var writeStream = await myFile.OpenStreamForWriteAsync())
    {
        // Option 1: Cast to stream and copy
        myBuffer.AsStream().CopyTo(writeStream);

        // Option 2: Cast to byte array and write
        var content = myBuffer.ToArray();
        writeStream.Write(content, 0, content.Length);
    }
}

参考:

于 2013-09-16T21:37:29.437 回答