[功能集锦] 001 - java下载文件
    @RequestMapping("/downloadxls.action")
    public void downloadxls(HttpServletRequest request, HttpServletResponse response) {
        //获取请求参数
        Map<String, Object> params = ParamsUtil.getParams(request);
        String contextPath = request.getSession().getServletContext().getRealPath(File.separator + "report");
        String excelName = xxxxx;
        String excelFullName = contextPath + File.separator + excelName + ".xls";
        InputStream inStream = null, fileInStream = null;
        ServletOutputStream outStream = null;
        int byteRead;
        try {
            fileInStream = new FileInputStream(excelFullName);
            inStream = new BufferedInputStream(fileInStream);
            response.reset();
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setHeader("Content-disposition", "attachment; filename=" + excelName + ".xls");
            outStream = response.getOutputStream();
            byte[] buffer = new byte[1024];
            while ((byteRead = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, byteRead);
            }
            response.flushBuffer();
            outStream.close();
            inStream.close();
            fileInStream.close();
        } catch (Exception e) {
            LOGGER.error( e);
        }finally{
            try {
                if(outStream!=null){
                    outStream.close();
                }
            } catch (IOException e2) {
                LOGGER.error(e2);
            }
            try {
                if(inStream!=null){
                    inStream.close();
                }
            } catch (IOException e2) {
                LOGGER.error(e2);
            }
            try {
                if(fileInStream!=null){
                    fileInStream.close();
                }
            } catch (IOException e2) {
                LOGGER.error(e2);
            }
        }
    }
[功能集锦] 001 - java下载文件的更多相关文章
- 【文件下载】Java下载文件的几种方式
		[文件下载]Java下载文件的几种方式 摘自:https://www.cnblogs.com/sunny3096/p/8204291.html 1.以流的方式下载. public HttpServl ... 
- java下载文件工具类
		java下载文件工具类 package com.skjd.util; import java.io.BufferedInputStream; import java.io.BufferedOutput ... 
- java下载文件时文件名出现乱码的解决办法
		转: java下载文件时文件名出现乱码的解决办法 2018年01月12日 15:43:32 橙子橙 阅读数:6249 java下载文件时文件名出现乱码的解决办法: String userAgent ... 
- Java 下载文件
		public @ResponseBody void exportExcel(HttpServletRequest request, HttpServletResponse response, Khxx ... 
- java下载文件demo
		java通过http方式下载文件 https://www.cnblogs.com/tiancai/p/7942201.html 
- Java下载文件(流的形式)
		@RequestMapping("download") @ResponseBody public void download(HttpServletResponse respons ... 
- Java下载文件的几种方式
		转发自博客园Sunny的文章 1.以流的方式下载 public HttpServletResponse download(String path, HttpServletResponse respon ... 
- java 下载文件的两种方式和java文件的上传
		一:以网络的方式下载文件 try { // path是指欲下载的文件的路径. File file = new File(path); // 以流的形式下载文件. InputStream fis = n ... 
- Java下载文件方法
		public static void download(String path, HttpServletResponse response) { try { // path是指欲下载的文件的路径. F ... 
随机推荐
- matplotlib学习记录  六
			# 绘制多数据条形图 # 假设你知道了列表a中电影分别在2017-09-14(b_14),2017-09-15(b_15), # 2017-09-16(b_16)三天的票房,为了展示列表中电影本身的票 ... 
- Linux和 Mac下git pull/push 免输入密码和账号
			linux下面可以直接创建.git-credential文件,命令如下: 创建文件,进入文件,输入内容: cd ~ touch .git-credentials vim .git-credential ... 
- BugBash活动分享
			此文已由作者夏君授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. BugBash源至微软概念,翻译为<缺陷大扫除>,顾名思义是集中大家力量全面清扫Bug,确保产品质 ... 
- 使用百度siteapp开发网站的App-(IOS和Android版本)
			介绍 之前写了个把百度云作文网站文件服务器.一些园友的评论不错.不过我似乎把意思弄错了! 我用的百度云的SVN环境! 现在不少人都做web开发.不管你是什么语言编写的(jsp,php,asp.net ... 
- TensorFlow batch normalize的使用
			TensorFlow batch normalize的使用 batch normalize 经常与CNN搭配使用,据一些研究表面,在RNN层数不是很深的时候使用batch normalize是会用损害 ... 
- [git 学习篇] git commit原理 --实践体会
			1 现对readme.txt作出修改,增加一行内容: Git has a mutable index called stage. Git is a distributed version contro ... 
- 九度oj 题目1459:Prime ring problem
			题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ... 
- Chromo开发常用插件和***工具
			地址:https://www.google.com/chrome/webstore/ ***工具:链接:http://pan.baidu.com/s/1pLakW7T 密码:2gpw Axure RP ... 
- ida动态调试笔记
			ida动态调试笔记 目标文件:阿里安全挑战赛的第二题 点击打开链接 使用环境:ida6.8点击打开链接,adt bundle点击打开链接 首先打开avd安卓模拟器,界面如下: 在dos下运行adb命令 ... 
- 前端CSS规范大全(转)
			一.文件规范 1.文件均归档至约定的目录中. 具体要求通过豆瓣的CSS规范进行讲解: 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用U ... 
