Springboot下载word文件无法打开
错误

话不多说直接上代码,正确word下载方式
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@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());
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
XWPFDocument document = new XWPFDocument(OPCPackage.open(inputStream));
document.write(response.getOutputStream());
inputStream.close();
}
|