创建大于150MB的ZIP文件会抛出OfMemoryException C#
客户机要求创建一个zip,该zip由放置在树状结构化文件夹中的多个文件组成。它最多包含150个文件。当这些文件在内存中超过大约160MB时,将引发OutOfMemoryException创建大于150MB的ZIP文件会抛出OfMemoryException C#,c#,asp.net-mvc,out-of-memory,heap-memory,icsharpcode,C#,Asp.net Mvc,Out Of Memory,Heap Memory,Icsharpcode,客户机要求创建一个zip,该zip由放置在树状结构化文件夹中的多个文件组成。它最多包含150个文件。当这些文件在内存中超过大约160MB时,将引发OutOfMemoryException 列表项 是否有配置来增加分配给此操作的内存 还有其他解决方法吗 示例代码 MemoryStream memStream = new MemoryStream(); using (var zipStream = new ZipOutputStream(memStream)) { foreach (FileMod
MemoryStream memStream = new MemoryStream();
using (var zipStream = new ZipOutputStream(memStream))
{
foreach (FileModel fileToBeAddedInZip in listOfFiles)
{
byte[] fileBytes;
fileBytes = //Read the file from DB
ZipEntry fileEntry = null;
fileEntry = new ZipEntry(fileToBeAddedInZip.fileName)
{
Size = fileBytes.Length
};
zipStream.PutNextEntry(fileEntry);
zipStream.Write(fileBytes, 0, fileBytes.Length);
}
}
zipStream.Flush();
zipStream.Close();
你必须在内存中完成吗?你运行这个的机器是否有足够的内存。。。基本上,约翰所说的,只是确保你考虑到它运行的地方。“SeabZiKKYES机器有足够的内存。即使在内存为16GB且仅使用了8.3GB的开发人员计算机中,也会出现同样的问题。visual studio默认为32位,请确保您的应用程序以64位运行。调试添加到mem缓冲区的行,查看它有多大。我猜是你在32位,但你也遇到了问题,约翰给了一个链接。我猜你是想避免记忆流,试试这样的