java IO流下载.docx文件时报文件损坏的错误,求解?
用java IO流从数据库中读取文件下载,以前下载.doc,.xls都没有问题。但是发现.docx. xlsx下载时,出现了文件损坏的提示。如下图:

点确定后,又弹出
,
我的代码如下:

点确定后,又弹出
,我的代码如下:
String fileId = request.getParameter("fileId");
AttachFileVO attachFileVO = new AttachFileVO();
attachFileVO.setFileId(fileId);
AttachFileVO attachFile = applicationService.getAttachFile(attachFileVO);
String fileName = attachFile.getFileName();
String formatFileName = CommonUtil.encodingFileName(fileName);
if(attachFile!=null&&attachFile.getFileContent()!=null){
InputStream in = null;
OutputStream os = null;
try{
response.reset();
response.setContentType(attachFile.getFileType());
response.setHeader("Content-Disposition", "attachment;filename="+formatFileName);
in = new ByteArrayInputStream(attachFile.getFileContent());
byte[] buffer = new byte[1024];
os = response.getOutputStream();
while (in.read(buffer) > 0) {
os.write(buffer);
}
}catch(Exception ex){
throw ex;
}finally{
if(in!=null){
in.close();
}
if(os!=null){
os.close();
}
}
return null;
}
...全文
相关推荐
POIOfDoc2Docx.zip
是通过poi转换doc变成docx的项目。代码是java代码。里面有所有的jar包依赖,不会出现问题。如果需要用maven,则可以根据里面的jar包版本获取maven依赖。
java异常解决方案.docx
java异常解决方案,应有尽有 各种异常,看了才知道!
java 读取 word pdf 等
JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法
2021-2022计算机二级等级考试试题及答案No.13899.docx
2021-2022计算机二级等级考试试题及答案No.13899.docx
2021-2022计算机二级等级考试试题及答案No.17099.docx
2021-2022计算机二级等级考试试题及答案No.17099.docx


Web 开发
