在Windows 8类库中将Stream写入文件

时间:2014-05-27 18:30:08

标签: c# file-io windows-8 winrt-xaml

我正在收到来自网络API的流。我想将此流写入存储文件。

1 个答案:

答案 0 :(得分:1)

您需要传递 FileStram FileName

 public async Task SaveToLocalFolderAsync(Stream file, string fileName)
    {
        StorageFolder localFolder = ApplicationData.Current.LocalFolder;
        StorageFile storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
        using (Stream outputStream = await storageFile.OpenStreamForWriteAsync())
        {
            await file.CopyToAsync(outputStream);
        }
    }

Saving a stream