【发布时间】:2012-08-20 13:33:31
【问题描述】:
我有一个大文件,它给我一个错误“抛出'System.OutOfMemoryException'类型的异常。”
任何人都有解决此问题的想法或解决方案。请帮忙。 示例代码....
private string GetSha1()
{
string filePath = txtFileName.Text;
byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
byte[] hashValue;
SHA1Managed hashString = new SHA1Managed();
string hex = "";
hashValue = hashString.ComputeHash(filebytes);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex;
}
我在上面代码的下面一行遇到异常......
byte[] filebytes = System.IO.File.ReadAllBytes(filePath);
filePath 的文件大小 > 500MB。
【问题讨论】:
-
您的系统是否运行 64 位操作系统?您的代码是为 64 位平台构建的吗?系统是否有几 GB 的可用内存?
-
@HABO - 我建议在这种情况下没关系,因为没有理由将整个文件同时放入内存。