关于07版导入失败的问题
title=刚发的 java.io.FileNotFoundException: D:\tomcat\apache-tomcat-8.5.37\temp\upload_c14002d4_3754_4f23_bd87_59054ef26a33_00000003.tmp (系统找不到指定的文件。) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.<init>(FileInputStream.java:138) content=null at org.apache.commons.fileupload.disk.DiskFileItem.getInputStream(DiskFileItem.java:206) at com.imooc.service.WordService.imp(WordService.java:45) at com.imooc.servlet.ImportWordServlet.doPost(ImportWordServlet.java:31) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
word为空,说什么文件未找到
package com.imooc.service; import com.imooc.dto.ImportWordParamDto; import com.imooc.dto.ImportWordResultDto; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import java.io.IOException; import java.util.List; public class WordService { public ImportWordResultDto imp(ImportWordParamDto dto) { //03版后缀为doc,07版为docx //返回给jsp的结果 ImportWordResultDto result = new ImportWordResultDto(); result.setTitle(dto.getTitle()); //创建03版对象 HWPFDocument doc = null; try { //创建doc文档 doc = new HWPFDocument(dto.getWord().getInputStream()); result.setContent(doc.getDocumentText().replace("\r", "<br>")); } catch (OfficeXmlFileException oe) { System.out.println("这可能是一个07版的word"); } catch (Exception e) { result.setMsg("这可能不是一个word"); } finally { if (doc != null) { try { doc.close(); //如果是03版则返回,否则执行下面的代码 return result; } catch (IOException e) { e.printStackTrace(); } } } //创建07版word XWPFDocument docx = null; try { docx = new XWPFDocument(dto.getWord().getInputStream()); //创建段落list List<XWPFParagraph> paragraphList = docx.getParagraphs(); //创建用于存放段落内容的字符串 StringBuilder content = new StringBuilder(); for (int i = 0; i < paragraphList.size(); i++) { //如果不是第一段就换行 if (i != 0) { content.append("<br>"); } content.append(paragraphList.get(i).getText()); } result.setContent(content.toString()); } catch (IOException e) { e.printStackTrace(); } finally { if (docx != null) { try { docx.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; } }
断点如下:
0
收起
正在回答 回答被采纳积分+1
2回答
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星