这是我将文件从一个文件写入另一个文件的代码。它适用于大小小于2GB的文件,但是当它的大小更大时抛出异常。因此,它复制少于2 GB的数据,然后抛出异常。任何修复?
const int bufferSize = 2048;
byte[] buffer = new byte[bufferSize];
int bytes = 0;
using (var input = filedata.DataStream)
using (var output = ServiceModel.FileManager.Current.GetFile(filedata.FileName).Open(FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
while ((bytes = input.Read(buffer, 0, bufferSize)) > 0) //Throws exception: An exception has been thrown when reading the stream.
{
output.Write(buffer, 0, bytes);
}
}