IO流-----写到输出流
Posted 编码龟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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流-----写到输出流的主要内容,如果未能解决你的问题,请参考以下文章
java内存流:java.io.ByteArrayInputStreamjava.io.ByteArrayOutputStreamjava.io.CharArrayReaderjava.io(代码片段