【发布时间】:2019-04-02 18:21:23
【问题描述】:
我不阅读大数据文本文件。我的文件大小约为 2GB。但是,我读取的最大文件大小为 200MB。这如何在 C# 中执行此操作。帮帮我。
private void button12_Click(object sender, EventArgs e)
{
String file = textBox1.Text;
if (string.IsNullOrEmpty(file))
{
MessageBox.Show("Файлыг заана уу!!");
}
else
{
System.IO.FileInfo fi = new System.IO.FileInfo(file);
System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open);
int bufferSize = 500000000; // file size
using (System.IO.BufferedStream bs = new System.IO.BufferedStream(fs, bufferSize))
{
byte [] buffer = new byte [bufferSize];
int readLength;
do
{
readLength = bs.Read(buffer, 0, bufferSize);
richTextBox1.Text += System.Text.Encoding.ASCII.GetString(buffer);
Application.DoEvents();
} while (readLength == bufferSize);
bs.Close();
}
fs.Close();
}
String names = richTextBox1.Text;
}
【问题讨论】:
-
当您尝试读取数据时会发生什么?你有例外吗?
-
读取600MB文件时,发生System.OutOfMemoryException错误。我知道这是一个内存问题。你对此有什么想法吗?
标签: c#