错误
话不多说直接上代码,正确word下载方式
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xwpf.usermodel.XWPFDocument; /** * 网络word文件获取到服务器后,经服务器处理后响应给前端 * * @param fileUrl * @param filename * @param response * @功能描述 网络文件获取到服务器后,经服务器处理后响应给前端 */ @RequestMapping("/netDownLoadNet") public void netDownLoadWordNet(String fileUrl, String filename, HttpServletResponse response) throws Exception { URL url = new URL(fileUrl); URLConnection conn = url.openConnection(); InputStream inputStream = conn.getInputStream(); response.setContentType(conn.getContentType()); //纯下载方式 文件名应该编码成UTF-8 response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); XWPFDocument document = new XWPFDocument(OPCPackage.open(inputStream)); document.write(response.getOutputStream()); inputStream.close(); }