public static void downLoadTxt(String fileName, HttpServletResponse response, List<String> message) throws IOException { try { response.setCharacterEncoding("UTF-8"); response.setHeader("content-Type", "text/plain"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".txt", "UTF-8")); BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream()); for(String msg : message){ msg+="\r\n"; byte[] buf = msg.getBytes(); output.write(buf); } response.flushBuffer(); output.close(); } catch (Exception e) { throw new IOException(e.getMessage()); } }
下载txt文件
最新推荐文章于 2024-03-29 20:28:23 发布