这是我将文件从一个文件写入另一个文件的代码。它适用于大小小于 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);
}
}