首页 > 代码库 > IO流-----写到输出流
IO流-----写到输出流
输出流:
/** * 方法名:writeStream * 方法描述:写到输出流 * @param title * @param wb * @param response * @param request * 返回值:void */ private static void writeStream(String title, HSSFWorkbook wb, HttpServletResponse response, HttpServletRequest request){ OutputStream os=null; try { String agent = request.getHeader("USER-AGENT"); title.replaceAll("/", "-"); // filename = new String(filename.getBytes("gbk"),"ISO8859_1"); if (agent.toLowerCase().indexOf("firefox")>0) { title = new String(title.getBytes("utf-8"), "iso-8859-1"); }else{ title = URLEncoder.encode(title, "UTF-8"); } response.reset(); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "attachment; filename="+title); response.setContentType("application/vnd.ms-excel;charset=utf-8"); // response.setContentType("application/octet-stream;charset=UTF-8"); os = new BufferedOutputStream(response.getOutputStream()); wb.write(os); } catch (Exception e) { e.printStackTrace(); } finally{ if(os!=null){ try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } }
IO流-----写到输出流
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。