/**
* 下载excel
* @param request
* @param response
* @param filePath
* @param fileName
*/
public static void download(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) {
response.setContentType("application/vnd.ms-excel");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
String recommendedName = new String(fileName.getBytes(), "iso_8859_1");//设置文件名称的编码格式
response.setHeader("Content-Disposition", "attachment; filename=" + recommendedName + ".xls");
bis = new BufferedInputStream(new FileInputStream(filePath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 下载word
* @param request
* @param response
* @param filePath
* @param fileName
*/
public void download(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) {
response.setContentType("application/x-msdownload;charset=UTF-8"); BufferedInputStream bis = null;
BufferedOutputStream bos = null; try {
response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("gbk"), "ISO8859-1"));
bis = new BufferedInputStream(new FileInputStream(filePath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
												

World、Excel利用流下载的更多相关文章

  1. Excel导出文件流下载

    Controller.cs @CrossOrigin(allowCredentials="true", allowedHeaders="*", methods= ...

  2. Android利用Http下载文件

    Android利用Http下载文件 一.场景 下载存文本文件和下载如mp3等大容量的文件 界面 二.代码编写 1.AndroidMainfest.xml中配置 主要是解决网络权限和写SDCard的权限 ...

  3. excel导入、下载功能

    1.excel导入.下载功能 2.首先,我们是居于maven项目进行开发引入poi,如果不是那就手动下载相应的jar包引入项目就可以了 <!-- poi --> <dependenc ...

  4. js 前端实现文件流下载的几种方式

    后端是用Java写的一个下载的接口,返回的是文件流,需求:点击,请求,下载 利用iframe实现文件流下载 //把上一次创建的iframe删掉,不然随着下载次数的增多页面上会一堆的iframe var ...

  5. java实现点击查询数据生成excel文件并下载

    须先导入关键maven包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi& ...

  6. asp.net将页面内容按需导入Excel,并设置excel样式,下载文件(解决打开格式与扩展名指定的格式不统一的问题)

    //请求一个excel类 Microsoft.Office.Interop.Excel.ApplicationClass excel = null; //创建 Workbook对象 Microsoft ...

  7. Java8新特性 1——利用流和Lambda表达式操作集合

    Java8中可以用简洁的代码来操作集合,比如List,Map,他们的实现ArrayList.以此来实现Java8的充分利用CPU的目标. 流和Lambda表达式都是Java8中的新特性.流可以实现对集 ...

  8. ASP.NET导出Excel(利用NPOI和EPPlus库,无需安装Office)

    网上提供了很多Asp.net中操作Excel的方法,其中大部分是调用微软的Office组件,下面提供三个无须安装Office即可从Asp.net输出Excel的方法. 1 简单方法 //下面代码输出的 ...

  9. Java 读取excel 文件流

    public static void initType(String path) { try { //1 获取excel文件流 excel xls 文件 暂不支持xlsx if (path.conta ...

随机推荐

  1. Spring_事务-注解代码

    applicationContext.xml <?xml version="1.0" encoding="UTF-8"?><beans xml ...

  2. Moore majority vote algorithm(摩尔投票算法)

    Boyer-Moore majority vote algorithm(摩尔投票算法) 简介 Boyer-Moore majority vote algorithm(摩尔投票算法)是一种在线性时间O( ...

  3. Rotate Image,N*N矩阵顺时针旋转90度

    public class RotateImage { public void rotate(int[][] matrix) { if(matrix.length == 1 && mat ...

  4. Search in Rotated Sorted Array, 查找反转有序序列。利用二分查找的思想。反转序列。

    问题描述:一个有序序列经过反转,得到一个新的序列,查找新序列的某个元素.12345->45123. 算法思想:利用二分查找的思想,都是把要找的目标元素限制在一个小范围的有序序列中.这个题和二分查 ...

  5. html5 如何打包成apk,将H5封装成android应用APK文件的几种方法

    直接使用编程软件提供的方法: 1.需要下载安装MyEclipse2014,Android SDK,eclipse(需配置Android开发环境) Java和Android环境安装与配置. 2.打开My ...

  6. HTTP Status 500 - Unable to instantiate Action, customerAction, defined for 'customer_toAddPage' i

    使用struts2时碰到这样的错误 HTTP Status 500 - Unable to instantiate Action, customerAction, defined for 'custo ...

  7. HTML5 ——web audio API 音乐可视化(二)

    上一篇 web audio API 音乐可视化(一)介绍了一些基本的API,以及如何简单的播放一个音频,本篇介绍一下怎么对获取到的音频进行分析,并将分析后的数据绘制成图像. 最终效果请戳这里; 完整版 ...

  8. VirtualizingPanel.IsVirtualizing 附加属性

    VirtualizingPanel.IsVirtualizing 附加属性 获取或设置一个值,该值指示此 VirtualizingPanel 正在虚拟化其子集合. 说明: 标准布局系统可以创建项容器并 ...

  9. tracecaller.cs

    #region Utility #if TRACE private const string Traceformat = "\"{0}\",\"{1:yyyy- ...

  10. jenkins集成maven实现自动化接口测试

    当时领导让研究这个,就总结了一个文档,现在记录在这里,给自己留个备份. 1.安装jenkins 地址http://updates.jenkins-ci.org/download/war/ 安装mave ...