我使用javaftp从FTP读取Excel文件,然后使用easyexcel解析,我总共有12个文件,其中8个文件读取解析成功,4个文件一直读取解析不成功,在本地打开文件没有问题。
读取本地windows机器上运行的项目没有问题,当项目部署到awsec2上的docker容器时,会出现以下问题。
FTP读取解析文件时出现以下错误。Excel解析从FTP读取的流时出现此问题。
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Could not open the specified zip entry source stream
at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:205)
at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:187)
at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:161)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:142)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:295)
at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.readOpcPackage(XlsxSaxAnalyser.java:141)
at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.<init>(XlsxSaxAnalyser.java:58)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.choiceExcelExecutor(ExcelAnalyserImpl.java:92)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.<init>(ExcelAnalyserImpl.java:45)
at com.alibaba.excel.ExcelReader.<init>(ExcelReader.java:143)
at com.alibaba.excel.read.builder.ExcelReaderBuilder.build(ExcelReaderBuilder.java:270)
at com.alibaba.excel.read.builder.ExcelReaderBuilder.doReadAll(ExcelReaderBuilder.java:274)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.zip.ZipException: invalid entry size (expected 134582 but got 134589 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:384)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:196)
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:220)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:132)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:56)
at org.apache.poi.openxml4j.opc.ZipPackage.openZipEntrySourceStream(ZipPackage.java:203)
从FTP读取文件代码如下:
ftp.changeWorkingDirectory(directory);
ftp.enterLocalPassiveMode();
return ftp.retrieveFileStream(downloadFile);
解析Excel文件方法:
EasyExcel.read(inputStream, DGBBExcelModel.class, new AnalysisEventListener<DGBBExcelModel>() {
@Override
public void invoke(DGBBExcelModel excelModel, AnalysisContext analysisContext) {
excelModel.setSourceFile(fileName);
result.add(excelModel);
if(result.size() >= 1000){
deliverGoodsRecordService.addBatch(result);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
try {
inputStream.close();
}catch (Exception e){
e.printStackTrace();
}
}
}).doReadAll();
2条答案
按热度按时间3bygqnnd1#
我遇到了同样的错误与我的Excel文件。
我在一个应用程序中使用了一个复制组件,导致复制的文件损坏。
我相信你的所作所为也导致了文件的损坏。
l3zydbqr2#
我刚刚将poi-ooxml和poi从3.17更新到4.1.2。问题解决了。