public void downloadTechNeed(String fid,String filename, HttpServletRequest request, HttpServletResponse response) { File targetFile = new File(otherFilePath + fid); if (ObjectUtils.isNotEmpty(targetFile) && targetFile.exists()) { java.io.OutputStream os = null; try { os = response.getOutputStream(); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=" + new String(filename.getBytes(), "ISO-8859-1")); response.addHeader("Content-Length", "" + targetFile.length()); response.setContentType(request.getServletContext().getMimeType(filename)); os.write(FileUtils.readFileToByteArray(targetFile)); os.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } } else { try { response.sendError(404); } catch (IOException e) { e.printStackTrace(); } } }
07-04
463
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)