c# – UWP:byte []到文件
作者:互联网
我有一个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,windows-phone,win-universal-app,windows-10-mobile 来源: https://codeday.me/bug/20190528/1167355.html