Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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# 读取大块的大文件#_C#_Streamreader - Fatal编程技术网

C# 读取大块的大文件#

C# 读取大块的大文件#,c#,streamreader,C#,Streamreader,我想逐块读取非常大的文件(4GBish) 我目前正在尝试使用StreamReader和Read()Read方法。语法是: sr.Read(char[] buffer, int index, int count) 因为索引是一个int,所以在我的例子中它将溢出。我应该用什么来代替呢?您可以尝试更简单的Read版本,它不会将流分块,而是逐个字符地读取。你必须实现自我分块,但这会给你更多的控制权,让你可以使用Long 索引是缓冲区的起始索引,而不是文件指针的索引,通常为零。在每次读取调用中,您将读取

我想逐块读取非常大的文件(4GBish)

我目前正在尝试使用
StreamReader
Read()
Read方法。语法是:

sr.Read(char[] buffer, int index, int count)

因为索引是一个
int
,所以在我的例子中它将溢出。我应该用什么来代替呢?

您可以尝试更简单的Read版本,它不会将流分块,而是逐个字符地读取。你必须实现自我分块,但这会给你更多的控制权,让你可以使用Long


索引是缓冲区的起始索引,而不是文件指针的索引,通常为零。在每次读取调用中,您将读取与
Read
方法的count参数相等的字符您不会一次读取所有文件,而是分块读取并使用该块。

要开始写入的缓冲区的索引

上面的示例将准备1024字节,并将写入控制台。您可以使用这些字节,例如使用
TCP
连接将这些字节发送到其他应用程序

在使用Read方法时,更有效的方法是使用 与流的内部缓冲区大小相同,其中 内部缓冲区设置为所需的块大小,并始终读取 小于块大小。如果内部缓冲区的大小为 构造流时未指定,其默认大小为4 千字节(4096字节)

这你。
char[] c = null;
while (sr.Peek() >= 0) 
{
    c = new char[1024];
    sr.Read(c, 0, c.Length);
    //The output will look odd, because 
    //only five characters are read at a time.
    Console.WriteLine(c);
}