大佬们遇到过这个问题吗?使用poi导出报java.io.IOException: Stream closed

导出excle结果一直报这个错误,是在找不到原因
privatevoidexportExcleFile(SXSSFWorkbookworkbook,HttpServletResponseresponse,StringexcleName)throwsException{
log.info("=====正在导出Excle=====");
try(OutputStreamoutputStream=response.getOutputStream()){
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-disposition","attachment;filename="+URLEncoder.encode(excleName,"UTF-8"));
response.addHeader("Pargam","no-cache");
response.addHeader("Cache-Control","no-cache");
workbook.write(outputStream);
response.flushBuffer();
workbook.dispose();
log.info("=====Excle导出完成=====");
}
}
java.io.IOException:Streamclosed
atjava.io.BufferedWriter.ensureOpen(BufferedWriter.java:116)~[na:1.8.0_211]
atjava.io.BufferedWriter.flushBuffer(BufferedWriter.java:126)~[na:1.8.0_211]
atjava.io.BufferedWriter.flush(BufferedWriter.java:253)~[na:1.8.0_211]
atorg.apache.poi.xssf.streaming.SheetDataWriter.close(SheetDataWriter.java:128)~[poi-ooxml-4.0.0.jar:4.0.0]
atorg.apache.poi.xssf.streaming.SXSSFSheet.getWorksheetXMLInputStream(SXSSFSheet.java:98)~[poi-ooxml-4.0.0.jar:4.0.0]
atorg.apache.poi.xssf.streaming.SXSSFWorkbook.injectData(SXSSFWorkbook.java:395)~[poi-ooxml-4.0.0.jar:4.0.0]
atorg.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:936)~[poi-ooxml-4.0.0.jar:4.0.0]
atcom.faujor.budget.service.impl.BudgetEditServiceImpl.exportExcleFile(BudgetEditServiceImpl.java:1177)~[classes/:na]
atcom.faujor.budget.service.impl.BudgetEditServiceImpl.exportData(BudgetEditServiceImpl.java:1152)~[classes/:na]
atcom.faujor.budget.service.impl.BudgetEditServiceImpl$$FastClassBySpringCGLIB$$52011bcc.invoke()~[classes/:na]
atorg.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atcom.faujor.budget.service.impl.BudgetEditServiceImpl$$EnhancerBySpringCGLIB$$2563fe0c.exportData()~[classes/:na]
atcom.faujor.budget.controller.BudgetEditController.exportData(BudgetEditController.java:216)~[classes/:na]
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_211]
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0_211]
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)~[na:1.8.0_211]
atjava.lang.reflect.Method.invoke(Method.java:498)~[na:1.8.0_211]
atorg.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atjavax.servlet.http.HttpServlet.service(HttpServlet.java:660)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atjavax.servlet.http.HttpServlet.service(HttpServlet.java:741)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)[tomcat-embed-websocket-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)[spring-boot-actuator-2.1.1.RELEASE.jar:2.1.1.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:117)[spring-boot-actuator-2.1.1.RELEASE.jar:2.1.1.RELEASE]
atorg.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:106)[spring-boot-actuator-2.1.1.RELEASE.jar:2.1.1.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)[tomcat-embed-core-9.0.13.jar:9.0.13]
atorg.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)[tomcat-embed-core-9.0.13.jar:9.0.13]
atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[na:1.8.0_211]
atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[na:1.8.0_211]
atorg.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-9.0.13.jar:9.0.13]
atjava.lang.Thread.run(Thread.java:748)[na:1.8.0_211]
导出来的excle提示有损坏,修复之后一条数据都没有
慕尼黑8549860
浏览 689回答 2
2回答

蛊毒传说

调用workbook.write(outputStream);的时候流已经被关闭了,问题不是出在你贴的这段代码里。检查一下调用这个方法前都对response做了哪些操作
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript