gpt4 book ai didi

windows-phone-8.1 - 复制大文件时如何避免 StorageFile.CopyAsync() 抛出异常?

转载 作者:行者123 更新时间:2023-12-04 14:58:36 24 4
gpt4 key购买 nike

我将通过 StorageFile.CopyAsync() 将一些文件从视频库复制到我的应用程序存储中方法,但如果文件大小超过 1GB,则会抛出如下异常:

Type: System.Runtime.InteropServices.COMException Message: Error HRESULT E_FAIL has been returned from a call to a COM component. Stacktrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()



如何导入大文件,是否有解决此问题的解决方案?

最佳答案

我会尝试通过缓冲区复制它 - 例如像这样:

private async Task CopyBigFile(StorageFile fileSource, StorageFile fileDest, CancellationToken ct)
{
using (Stream streamSource = await fileSource.OpenStreamForReadAsync())
using (Stream streamDest = await fileDest.OpenStreamForWriteAsync())
await streamSource.CopyToAsync(streamDest, 1024, ct);
return;
}

关于windows-phone-8.1 - 复制大文件时如何避免 StorageFile.CopyAsync() 抛出异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866325/

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