如果文件包含图像,Apache POI会显示异常

时间:2016-01-03 07:18:54

标签: java apache-poi

我使用Apache POI来读取.doc文件。如果.doc文件包含图像,则代码最终会出现异常。没有图像的文件可以成功读取并输出。

我的代码如下。

File file = null;
WordExtractor extractor = null ;
String res="";
try 
{
    file = new File("E:\\MCA\\S5\\Mini Project\\trial.doc");
    FileInputStream fis=new FileInputStream(file.getAbsolutePath());
    HWPFDocument document=new HWPFDocument(fis);
    extractor = new WordExtractor(document);
    String [] fileData = extractor.getParagraphText();
    for(int i=0;i<fileData.length;i++)
    {
    fileData[i]=fileData[i].trim();
    out.println(fileData[i]);            
    }
 }

catch(Exception exep)
{
    out.println(exep.getMessage());
}

该异常在

处触发
HWPFDocument document=new HWPFDocument(fis);

例外:

  org.apache.jasper.JasperException: An exception occurred processing JSP page /word_read.jsp at line 23

20: {
21:     file = new File("E:\\MCA\\S5\\Mini Project\\trial.doc");
22:     FileInputStream fis=new FileInputStream(file.getAbsolutePath());
23:     HWPFDocument document=new HWPFDocument(fis);
24:     extractor = new WordExtractor(document);
25:     String [] fileData = extractor.getParagraphText();
26:     for(int i=0;i<fileData.length;i++)


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause

javax.servlet.ServletException: java.lang.NoSuchFieldError: filesystem
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:906)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:835)
    org.apache.jsp.word_005fread_jsp._jspService(word_005fread_jsp.java:121)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause

java.lang.NoSuchFieldError: filesystem
    org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:216)
    org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:157)
    org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:145)
    org.apache.jsp.word_005fread_jsp._jspService(word_005fread_jsp.java:91)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

0 个答案:

没有答案