导出功能
< 返回列表时间: 2019-01-17来源:OSCHINA
【围观】麒麟芯片遭打压成绝版,华为亿元投入又砸向了哪里?>>> public void downloadD(HttpServletRequest request, HttpServletResponse res, String contractName, String contractPath) throws IOException { // FileAttach fileAttach = fileAttachService.getFileAttachById(fileId); OutputStream os = res.getOutputStream(); try { res.reset(); String fileName = URLEncoder.encode(contractName, "UTF-8"); /* * see http://support.microsoft.com/default.aspx?kbid=816868 */ if (fileName.length() > 150) { String guessCharset = "gb2312"; /*根据request的locale 得出可能的编码,中文操作系统通常是gb2312*/ fileName = new String(contractName.getBytes(guessCharset), "ISO8859-1"); } res.setHeader("Content-Disposition", "attachment; filename=" + fileName); res.setContentType("application/octet-stream; charset=utf-8"); String path = request.getSession().getServletContext() .getRealPath("/"); File dirPath = new File(path +"/"+ contractPath); os.write(FileUtils.readFileToByteArray(dirPath)); os.flush(); } finally { if (os != null) { os.close(); } } }
热门排行