javaweb reponse 写出文件
Map map = getSearchValue();File excelFile = orderService.getexportexcel(id,map);InputStream is = null;OutputStream os = null;BufferedInputStream bis = null;BufferedOutputStream bos = null;//以流的形式输出文件try {if (excelFile.exists()) {String fileName = "订单.xls";is = new FileInputStream(excelFile);HttpServletResponse response = ServletActionContext.getResponse();os = response.getOutputStream();bis = new BufferedInputStream(is);bos = new BufferedOutputStream(os);fileName = java.net.URLEncoder.encode(fileName, "UTF-8");// 处理中文文件名的问题// fileName = new String(fileName.getBytes("UTF-8"), "GBK");// 处理中文文件名的问题response.reset();response.setCharacterEncoding("UTF-8");response.setContentType("application/ vnd.ms-excel");// 不同类型的文件对应不同的MIME类型response.setHeader("Content-Disposition","attachment; filename=" + fileName);int bytesRead = 0;byte[] buffer = new byte[1024];while ((bytesRead = bis.read(buffer)) != -1) {bos.write(buffer, 0, bytesRead);// 将文件发送到客户端}bos.flush();}} catch (Exception e) {logger.error(e.getMessage(), e);} finally{IOUtils.closeQuietly(bis);IOUtils.closeQuietly(bos);IOUtils.closeQuietly(is);IOUtils.closeQuietly(os);}
javaweb reponse 写出文件的更多相关文章
- 将基因组数据分类并写出文件,python,awk,R data.table速度PK
由于基因组数据过大,想进一步用R语言处理担心系统内存不够,因此想着将文件按染色体拆分,发现python,awk,R 语言都能够非常简单快捷的实现,那么速度是否有差距呢,因此在跑几个50G的大文件之前, ...
- 使用dom4j工具:XMLWriter写出文件(五)
package dom4j_write; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStre ...
- java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- 将JSON对象带有格式的写出到文件中
需求:将一个JSON对象写出到文件中,要求文件中的JSON数据带有简单的格式.代码的实现参考了Java算法中的栈处理括号匹配问题.好了,不多说了,下面是代码的实现. 代码: package gemu. ...
- Objective-C写出Json文件(可作配置文件)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #008f00 } span. ...
- 【java】File的使用:将字符串写出到本地文件,大小0kb的原因
实现方法: 暂时写一种方法,将字符串写出到本地文件,以后可以补充更多种方法: public static void main(String[] args) { /** * ============== ...
- java里如何使用输入流和输出流实现读取本地文件里内容和写出到本地文件里
不多说,直接上干货! 第一种方法 PWDemo.java package zhouls.bigdata.DataFeatureSelection.filter; import java.io.File ...
- (数据科学学习手札143)为geopandas添加gdb文件写出功能
本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,很多读者朋友跟随着我先前写作的 ...
- c# .net获取文件夹下的所有文件(多层递归),并获取区间数据(Jsion,xml等数据)写出到处理文件,学习分享~
static void Main(string[] args) { string path = string.Format(@"C:\Users\Administrator\D ...
随机推荐
- dynamic bone unity github
https://github.com/unity3d-jp/unitychan-crs 我发现我总找不到以前的东西.. https://www.cnblogs.com/alps/p/8284577.h ...
- JavaScript逻辑and、or、not运算符详解
一.AND详解: 在JavaScript中,逻辑 AND 运算符用双和号(&&)表示. 需要说明的是:逻辑AND运算的运算数可以是任何类型的,不止是Boolean值,如果某个运算数不是 ...
- J2EE 中 用 El表达式 和 Jsp 方式 取得 URL 中的参数方法
使用 el表达式方法: var urlParamValue = "${param.urlVarName}"; 使用 Jsp 表达式 var urlParamValue2 = &qu ...
- Java开发新手经常遇到的一些问题
A:java.lang.UnsupportedClassVersionError: Bad version number in .class file 解答:导致此问题的原因是Tomcat运行的JDK ...
- (转)Behavior Tree实践
http://www.cnblogs.com/mavaL/archive/2013/04/07/3001860.html
- [NPM] Avoid Duplicate Commands by Calling one NPM Script from Another
We can get a lot of utility through CLI tools invoked via npm scripts. Many of these tools have APIs ...
- (剑指Offer)面试题54:表示数值的字符串
题目: 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3.14 ...
- 在github Pages上部署octopress搭建个人博客系统
原文链接:http://caiqinghua.github.io/blog/2013/08/26/deploy-octopress-to-github-pages/ 引子 上一篇博客已经说了为什么要搭 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- CSS布局之脱离文档流详解——浮动、绝对定位脱离文档流的区别
1.代码 (1)示例代码1 <!DOCTYPE html> <html lang="zh"> <head> <meta charset=& ...