本文介绍了复制大文件时如何避免 StorageFile.CopyAsync() 抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I'm going to copy some files from Video Library to my app storage through StorageFile.CopyAsync() method, but if a file's size is more than 1GB, it would throw an exception as follow:

类型:System.Runtime.InteropServices.COMException 消息:错误HRESULT E_FAIL 已从对 COM 组件的调用返回.堆栈跟踪:在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

如何导入一个大文件,有没有办法解决这个问题?

How can I import a big file, Is there have a solution to solve this problem?

推荐答案

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

I would try to copy it via buffer - for example like this:

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;
}

这篇关于复制大文件时如何避免 StorageFile.CopyAsync() 抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:18