这是我读取文本文件的代码,该文件恰好大于 1GB 并且以竖线分隔:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string strFilePath = @"C:\Users\Me\Desktop\123.txt";
private void button1_Click(object sender, EventArgs e)
{
var arrRawData = File.ReadLines(strFilePath).Select(line => line.Split('|')).ToArray();
}
}
}
当我点击按钮时出现这个错误:
"System.OutOfMemoryException' occurred in mscorlib.dll"
我有 16GB 的 RAM...我做错了什么?
最佳答案
您的程序在 32 位模式下运行。这将永远不允许读取超过 650 兆字节的数据,这大约是地址空间中可用的最大尺寸空洞。
项目 + 属性,构建选项卡,取消选中“首选 32 位”选项。
请注意,几乎所有解析文件数据的应用程序都不需要使用这么多内存。使用 StreamReader 类一次只读一行。
关于c# - Visual Studio 2012 Express 对读取大文件有限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14266823/