System.OverflowException: 数组维度超过了支持的范围。
System.OverflowException: 数组维度超过了支持的范围。
Code:
1 | FileStream fs = File.OpenRead(file); |
日志:
[2023-09-25 15:21:23.196 +08:00] [ERR] 文件压缩失败!
文件:H:\slpk\345slpk\
System.OverflowException: 数组维度超过了支持的范围。
在 cim_dgp.Common.DirectoryUtil.ZipCompress(String strFile, ZipOutputStream outstream, String staticFile) 位置 E:\project\wuchuan\code\cim-dgp\cim_dgp\cim_dgp.Common\DirectoryHelper\DirectoryUtil.cs:行号 594
在 cim_dgp.Common.DirectoryUtil.DirectoryZip(String strFile, String strZip) 位置 E:\project\wuchuan\code\cim-dgp\cim_dgp\cim_dgp.Common\DirectoryHelper\DirectoryUtil.cs:行号 559
问题定位:
byte[] buffer = new byte[fs.Length];
原因:
文件过大时,使用文件流长度创建数组,内存溢出;
解决:分块读取
1 | string relativePath = Path.GetRelativePath(rootFolder, file); |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 WineMonk!
评论