Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 读取大文件时出现IOException_C#_.net_Exception Handling - Fatal编程技术网

C# 读取大文件时出现IOException

C# 读取大文件时出现IOException,c#,.net,exception-handling,C#,.net,Exception Handling,这是我将文件从一个文件写入另一个文件的代码。它适用于大小小于2GB的文件,但当文件大小较大时会引发异常。所以它复制少于2GB的数据,然后抛出异常。有办法吗 const int bufferSize = 2048; byte[] buffer = new byte[bufferSize]; int bytes = 0; using (var input = filedata.DataStream) using (var output = ServiceModel.FileManager.Curre

这是我将文件从一个文件写入另一个文件的代码。它适用于大小小于2GB的文件,但当文件大小较大时会引发异常。所以它复制少于2GB的数据,然后抛出异常。有办法吗

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

您声明只将写入文件,然后从中读取。哪种类型是“输出”和“输入”?'“var”在这里没有帮助。。。你能粘贴你的例外情况吗?