我有1.5 GB的文件進行測試,並能複製的例外(我在的Windows Phone 8.1測試它)。手動設置內部緩衝區大小似乎可以解決問題,但請注意這會影響應用程序。 Read under the Buffer section on MSDN on dealing with large data sets.
的CreateNewFileAsync()方法簡單地創建一個新的文件:
祝您好運和快樂編碼。
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("largeFile.txt");
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
// Exception
if (file != null)
{
StorageFile copiedFile = await file.CopyAsync(tempFolder, "copied.txt", NameCollisionOption.GenerateUniqueName);
}
// Setting the internal buffer to 1024
// Be aware- from MSDN: However, this buffer is allocated on the large object heap
// and could potentially degrade garbage collection performance.
// You should only use large buffer sizes if it will noticeably improve the performance of your app.
var newFile = await CreateNewFileAsync();
using (Stream ss = await file.OpenStreamForReadAsync())
using (Stream sd = await newFile.OpenStreamForWriteAsync())
{
await ss.CopyToAsync(sd, 1024);
var fileProps = await file.GetBasicPropertiesAsync();
var size = fileProps.Size;
}
答案可以在這裏找到: [http://stackoverflow.com/a/23866856/374075](http://stackoverflow.com/a/23866856/374075) 您需要來緩衝它 – Chris 2014-12-05 14:40:33
這兩種方法都使用緩衝區,CopyToAsync只是讓我們設置內部緩衝區的大小。 TBH我不知道爲什麼緩衝區大小在默認情況下(我相信大約20 KB左右,但不確定)拋出異常,並且該方法是異步的。我會小心設置內部緩衝區太高。 – 2014-12-05 16:01:07