本帖子沒有答案,只是說一下坑,余下的自己決定。
Caused by: java.lang.IllegalStateException: Zip File is closed
at org.apache.poi3.openxml4j.util.ZipFileZipEntrySource.getEntries(ZipFileZipEntrySource.java:45)
at org.apache.poi3.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:161)
at org.apache.poi3.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:662)
at org.apache.poi3.openxml4j.opc.OPCPackage.open(OPCPackage.java:223)
at org.apache.poi3.openxml4j.opc.OPCPackage.open(OPCPackage.java:186)
at com.iss.itms.util.excel.BigDataParseExcelUtil.process(BigDataParseExcelUtil.java:85)
at com.iss.itms.ebankcertificate.EbankCertificateOperate.impdata(EbankCertificateOperate.java:405)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.toft.core2.service.ServiceManager.callService(ServiceManager.java:74)
... 61 more
我代碼這個位置EbankCertificateOperate.impdata(EbankCertificateOperate.java:405)進行了解析傳來的路徑。
這個錯誤的原因是路徑錯誤,就是傳來的excel的路徑錯誤。
具體的原因就是你的路徑是在瀏覽器中選擇獲得的路徑,但是大部分瀏覽器都進行了路徑安全處理;就是路徑都替換成了(C:\fakepath\---),然后就報錯了。
其中一個方法:通過一下jsp代碼可以獲得絕對地址:
//附帶不用修改瀏覽器安全配置的javascript代碼,兼容ie, firefox全系列 function getPath(obj) { if(obj) { if (window.navigator.userAgent.indexOf("MSIE")>=1) { obj.select(); return document.selection.createRange().text; } else if(window.navigator.userAgent.indexOf("Firefox")>=1) { if(obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } //參數obj為input file對象
通過以上我本地成功了,但是部署測試環境也是不行。
網上找到的方法都沒解決,我就用流的方式。但還是報錯a.io.IOException: Unable to read entire header; 0 bytes read; expected 512 bytes,這個沒找到方法。
最后我就有用了普通方法導入的excel。
大數據量導入的方法見我另一個博客:https://www.cnblogs.com/daguozb/p/10031970.html,在OPCPackage pkg = OPCPackage.open(filename);這里發生的錯誤。
寫本博客目的雖然沒解決大家的問題,只是提供我處理的過程參考參考,避免浪費更多的時間。