首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

生成可保存途径的文件的方法

2012-12-22 
生成可保存路径的文件的方法// 向页面写文件private void writeFile(List list, String tableName) {HttpS

生成可保存路径的文件的方法

// 向页面写文件private void writeFile(List list, String tableName) {HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);StringBuffer sb = new StringBuffer();// 定义要写入文件的内容for (int i = 0; i < list.size(); i++) {sb.append(list.get(i).toString());sb.append("\r\n");}// 文件输出方式response.setContentType("application/sql");response.setHeader("Content-disposition", "attachment;filename="+ tableName + ".sql");BufferedOutputStream bos = null;try {bos = new BufferedOutputStream(response.getOutputStream());bos.write(sb.toString().getBytes());bos.flush();} catch (IOException e) {e.printStackTrace();} finally {if (bos != null) {try {bos.close();} catch (IOException e) {e.printStackTrace();}}}}
?

热点排行