我正在尝试使用Apache POI读取Word文档(.docx),它给了我这个错误...
线程“ AWT-EventQueue-0”中的异常java.lang.NoClassDefFoundError:org / apache / commons / compress / utils / InputStreamStatistics在org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream(ZipArchiveThresholdInputStream.java:63)在org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:178)在org.apache.poi.openxml4j.opc.ZipPackage(ZipPackage.java:104)在org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:301)在gui.CryptoGUI.selectFileButtonActionPerformed(CryptoGUI.java:645)在gui.CryptoGUI.access $ 1100(CryptoGUI.java:27)在gui.CryptoGUI $ 11.actionPerformed(CryptoGUI.java:321)在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348)在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)在com.jtattoo.plaf.BaseButtonListener.mouseReleased(BaseButtonListener.java:65)在java.awt.Component.processMouseEvent(Component.java:6535)在javax.swing.JComponent.processMouseEvent(JComponent.java:3324)在java.awt.Component.processEvent(Component.java:6300)在java.awt.Container.processEvent(Container.java:2236)在java.awt.Component.dispatchEventImpl(Component.java:4891)在java.awt.Container.dispatchEventImpl(Container.java:2294)在java.awt.Component.dispatchEvent(Component.java:4713)在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)在java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)在java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)在java.awt.Container.dispatchEventImpl(Container.java:2280)在java.awt.Window.dispatchEventImpl(Window.java:2750)在java.awt.Component.dispatchEvent(Component.java:4713)在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)在java.awt.EventQueue.access $ 500(EventQueue.java:97)在java.awt.EventQueue $ 3.run(EventQueue.java:709)在java.awt.EventQueue $ 3.run(EventQueue.java:703)在java.security.AccessController.doPrivileged(本机方法)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)在java.awt.EventQueue $ 4.run(EventQueue.java:731)在java.awt.EventQueue $ 4.run(EventQueue.java:729)在java.security.AccessController.doPrivileged(本机方法)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)在java.awt.EventQueue.dispatchEvent(EventQueue.java:728)在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
我的类路径中有下面的库,
这是我收到此错误的代码
private void selectFileButtonActionPerformed(java.awt.event.ActionEvent evt) {
final JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
int returnValue = jfc.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
FileInputStream fis = null;
try {
selectedFile = jfc.getSelectedFile();
fileNameText.setText(selectedFile.getAbsolutePath());
double bytes = selectedFile.length();
double kilobytes = (bytes / 1024);
fileSizeLabel.setText("Size : " + (Math.round(kilobytes * 100.0) / 100.0) + " KB");
fis = new FileInputStream(selectedFile);
XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis)); // EXCEPTION THROWS FROM HERE
XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
System.out.println(extractor.getText());
} catch (FileNotFoundException ex) {
Logger.getLogger(CryptoGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(CryptoGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvalidFormatException ex) {
Logger.getLogger(CryptoGUI.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(CryptoGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
好像我缺少一个库,但我想我已经添加了为此所需的一切。我在这里想念什么?
如链接的问题所述,POI页面是一个很好的资源。 what all are the jar dependencies for apache POI for read and write to excel or xls?
不幸的是,从Google或Apache POI网站本身很难到达那里。 http://poi.apache.org/components/index.html#components