我正在使用OdfToolkit读取 xls 文件和 odf 类型文件。以InputStream
读取文件时出现异常。下面提供了我正在使用的阅读方法。
// store the file received in the server before processing
File file = new File("/path/to/stored-file-with-different-name");
multipartFile.transferTo(file);
FileInputStream fileInputStream = new FileInputStream(new File("stored-file-with-different-name");
SpreadsheetDocument.loadDocument(fileInputStream);
我得到的异常如下。
Caused by: java.lang.IllegalArgumentException: org.odftoolkit.odfdom.pkg.OdfValidationException; The ODF package shall be a ZIP file!
at org.odftoolkit.odfdom.pkg.OdfPackage.readZip(OdfPackage.java:451)
at org.odftoolkit.odfdom.pkg.OdfPackage.initializeZip(OdfPackage.java:425)
at org.odftoolkit.odfdom.pkg.OdfPackage.<init>(OdfPackage.java:285)
at org.odftoolkit.odfdom.pkg.OdfPackage.loadPackage(OdfPackage.java:335)
at org.odftoolkit.simple.Document.loadDocument(Document.java:303)
at org.odftoolkit.simple.SpreadsheetDocument.loadDocument(SpreadsheetDocument.java:156)
...
Caused by: org.odftoolkit.odfdom.pkg.OdfValidationException; The ODF package shall be a ZIP file!
at org.odftoolkit.odfdom.pkg.OdfPackage.readZip(OdfPackage.java:447)
...
fileInputStream
是由Spring引导中的MultipartFile
文件构造而成的。