gpt4 book ai didi

c# - UWP : byte[] to file

转载 作者:太空狗 更新时间:2023-10-30 01:02:00 25 4
gpt4 key购买 nike

我有一个byte[],我想将它存储到一个文件中。这是我的代码:

using System.Runtime.InteropServices.WindowsRuntime;

StorageFolder folder = await GetStorageFolderFromFilePath(filePath);
StorageFile file = await folder.CreateFileAsync(Path.GetFileName(filePath), CreationCollisionOption.ReplaceExisting);

using (Stream stream = await file.OpenStreamForWriteAsync())
{
IBuffer buffer = byteArray.AsBuffer();
await FileIO.WriteBufferAsync(file, buffer);
}

文件已创建,但文件为空。我做错了什么?

最佳答案

为什么不使用 FileIO.WriteBytesAsync 方法?

public static IAsyncAction WriteBytesAsync(IStorageFile file, System.Byte[] buffer);

你可以在一行代码中完成:

await FileIO.WriteBytesAsync(storageFile, byteArray);

关于c# - UWP : byte[] to file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36086056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com