1. Map map = getSearchValue();
  2. File excelFile = orderService.getexportexcel(id,map);
  3. InputStream is = null;
  4. OutputStream os = null;
  5. BufferedInputStream bis = null;
  6. BufferedOutputStream bos = null;
  7. //以流的形式输出文件
  8. try {
  9. if (excelFile.exists()) {
  10. String fileName = "订单.xls";
  11. is = new FileInputStream(excelFile);
  12. HttpServletResponse response = ServletActionContext
  13. .getResponse();
  14. os = response.getOutputStream();
  15. bis = new BufferedInputStream(is);
  16. bos = new BufferedOutputStream(os);
  17. fileName = java.net.URLEncoder.encode(fileName, "UTF-8");// 处理中文文件名的问题
  18. // fileName = new String(fileName.getBytes("UTF-8"), "GBK");// 处理中文文件名的问题
  19. response.reset();
  20. response.setCharacterEncoding("UTF-8");
  21. response.setContentType("application/ vnd.ms-excel");// 不同类型的文件对应不同的MIME类型
  22. response.setHeader("Content-Disposition",
  23. "attachment; filename=" + fileName);
  24. int bytesRead = 0;
  25. byte[] buffer = new byte[1024];
  26. while ((bytesRead = bis.read(buffer)) != -1) {
  27. bos.write(buffer, 0, bytesRead);// 将文件发送到客户端
  28. }
  29. bos.flush();
  30. }
  31. } catch (Exception e) {
  32. logger.error(e.getMessage(), e);
  33. } finally{
  34. IOUtils.closeQuietly(bis);
  35. IOUtils.closeQuietly(bos);
  36. IOUtils.closeQuietly(is);
  37. IOUtils.closeQuietly(os);
  38. }


javaweb reponse 写出文件的更多相关文章

  1. 将基因组数据分类并写出文件,python,awk,R data.table速度PK

    由于基因组数据过大,想进一步用R语言处理担心系统内存不够,因此想着将文件按染色体拆分,发现python,awk,R 语言都能够非常简单快捷的实现,那么速度是否有差距呢,因此在跑几个50G的大文件之前, ...

  2. 使用dom4j工具:XMLWriter写出文件(五)

    package dom4j_write; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStre ...

  3. java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...

  4. 将JSON对象带有格式的写出到文件中

    需求:将一个JSON对象写出到文件中,要求文件中的JSON数据带有简单的格式.代码的实现参考了Java算法中的栈处理括号匹配问题.好了,不多说了,下面是代码的实现. 代码: package gemu. ...

  5. Objective-C写出Json文件(可作配置文件)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #008f00 } span. ...

  6. 【java】File的使用:将字符串写出到本地文件,大小0kb的原因

    实现方法: 暂时写一种方法,将字符串写出到本地文件,以后可以补充更多种方法: public static void main(String[] args) { /** * ============== ...

  7. java里如何使用输入流和输出流实现读取本地文件里内容和写出到本地文件里

    不多说,直接上干货! 第一种方法 PWDemo.java package zhouls.bigdata.DataFeatureSelection.filter; import java.io.File ...

  8. (数据科学学习手札143)为geopandas添加gdb文件写出功能

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,很多读者朋友跟随着我先前写作的 ...

  9. c# .net获取文件夹下的所有文件(多层递归),并获取区间数据(Jsion,xml等数据)写出到处理文件,学习分享~

    static void Main(string[] args)        { string path = string.Format(@"C:\Users\Administrator\D ...

随机推荐

  1. dynamic bone unity github

    https://github.com/unity3d-jp/unitychan-crs 我发现我总找不到以前的东西.. https://www.cnblogs.com/alps/p/8284577.h ...

  2. JavaScript逻辑and、or、not运算符详解

    一.AND详解: 在JavaScript中,逻辑 AND 运算符用双和号(&&)表示. 需要说明的是:逻辑AND运算的运算数可以是任何类型的,不止是Boolean值,如果某个运算数不是 ...

  3. J2EE 中 用 El表达式 和 Jsp 方式 取得 URL 中的参数方法

    使用 el表达式方法: var urlParamValue = "${param.urlVarName}"; 使用 Jsp 表达式 var urlParamValue2 = &qu ...

  4. Java开发新手经常遇到的一些问题

    A:java.lang.UnsupportedClassVersionError: Bad version number in .class file 解答:导致此问题的原因是Tomcat运行的JDK ...

  5. (转)Behavior Tree实践

    http://www.cnblogs.com/mavaL/archive/2013/04/07/3001860.html

  6. [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 ...

  7. (剑指Offer)面试题54:表示数值的字符串

    题目: 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3.14 ...

  8. 在github Pages上部署octopress搭建个人博客系统

    原文链接:http://caiqinghua.github.io/blog/2013/08/26/deploy-octopress-to-github-pages/ 引子 上一篇博客已经说了为什么要搭 ...

  9. poj 3311 Hie with the Pie dp+状压

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 ...

  10. CSS布局之脱离文档流详解——浮动、绝对定位脱离文档流的区别

    1.代码 (1)示例代码1 <!DOCTYPE html> <html lang="zh"> <head> <meta charset=& ...