public static void down(HttpServletRequest request,
   HttpServletResponse
response) throws Exception {
  
  
  String name="aaa.*";//文件名
  String uploadPath =
UploadFileHelper.getRepositoryPath()+"//";//文件来源

String
filePath = name;
  String fileName = name;
  
  
  if
(request.getHeader("User-Agent").toLowerCase().indexOf("firefox")
> 0){
   fileName =
new String(fileName.getBytes("UTF-8"),
"ISO8859-1");//firefox浏览器
  }else {
      
if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE")
> 0){
     
  fileName = URLEncoder.encode(fileName,
"UTF-8");//IE浏览器
      
}
  }

response.setContentType("text/plain");

response.setHeader("Location",fileName);

response.reset();
  response.setHeader("Cache-Control",
"max-age=0" );
  response.setHeader("Content-Disposition",
"attachment; filename=" + fileName);
 BufferedInputStream bis = null;
  BufferedOutputStream bos =
null;
  OutputStream fos = null;
  InputStream fis = null;
  filePath = uploadPath +
filePath;
  fis = new
FileInputStream(filePath);
    
bis = new BufferedInputStream(fis);
    
fos = response.getOutputStream();
    
bos = new BufferedOutputStream(fos);

int bytesRead = 0;
    
byte[] buffer = new byte[5 * 1024];
    
while ((bytesRead = bis.read(buffer)) != -1) {
        
bos.write(buffer, 0, bytesRead);// 将文件发送到客户端
    
}
    
bos.close();
    
bis.close();
    
fos.close();
    
fis.close();

}

java 下载文件功能代码例子的更多相关文章

  1. java下载文件工具类

    java下载文件工具类 package com.skjd.util; import java.io.BufferedInputStream; import java.io.BufferedOutput ...

  2. php下载文件的代码示例

    php下载文件的代码示例,需要的朋友可以参考下 <?php  $file = 'monkey.gif';  if (file_exists($file)) {  header('Content- ...

  3. 【文件下载】Java下载文件的几种方式

    [文件下载]Java下载文件的几种方式  摘自:https://www.cnblogs.com/sunny3096/p/8204291.html 1.以流的方式下载. public HttpServl ...

  4. springboot项目下载文件功能中-切面-导致的下载文件失败的bug

    背景:使用spring提供的 ResponseEntity 和Resource结合,实现的下载文件功能 bug:Resource已经加载到了文件, 并且通过 ResponseEntity 构建了响应, ...

  5. java下载文件时文件名出现乱码的解决办法

    转: java下载文件时文件名出现乱码的解决办法 2018年01月12日 15:43:32 橙子橙 阅读数:6249   java下载文件时文件名出现乱码的解决办法: String userAgent ...

  6. 批量去除Teleport Pro整站下载文件冗余代码

    teleport pro tppabs标签批量删除 teleport pro tppabs标签批量删除 使 用Teleport Pro下载的网页代码中包含了很多垃圾代码,比如下载的html网页代码中会 ...

  7. Java 下载文件

    public @ResponseBody void exportExcel(HttpServletRequest request, HttpServletResponse response, Khxx ...

  8. java下载文件demo

    java通过http方式下载文件 https://www.cnblogs.com/tiancai/p/7942201.html

  9. Java下载文件(流的形式)

    @RequestMapping("download") @ResponseBody public void download(HttpServletResponse respons ...

随机推荐

  1. getDefinitionByName与ApplicationDomain.getDefinition

    主swf 定义:MC,被加载swf 定义:MC.MC1 ①父SWF的应用程序域的新建子域 (默认方式)称其为应用程序域的继承 var app:ApplicationDomain=new Applica ...

  2. Ubuntu 15.04下MySQL 5.6.25不支持中文解决办法

    Ubuntu 15.04下MySQL 5.6.25不支持中文解决办法,apt-get install 安装的,不是源码包安装的mysql. 1 修改mysql的配置文件 /etc/mysql/conf ...

  3. Note of IOS 7 - Views

    1. Views presentation: A view (an object whose class is UIView or a subclass of UIView) knows how to ...

  4. cdoj 1136 邱老师玩游戏 树形背包

    邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1136 Desc ...

  5. Unable to automatically debug "XXXXX“

    I solved this issue by going to C:\Program Files\Microsoft VisualStudio10.0\Common7\IDE then running ...

  6. Jetty学习(一)

           最近做一个项目,需要动态添加与移除servlet容器的http端口,并且启动都是嵌入式的.因此,果断选择了Jetty.        在模块化方面,Jetty是做的相当给力的一个容器,对 ...

  7. 【ZZ】Python入门神图

    http://mp.weixin.qq.com/s?__biz=MzA3OTIxNTA0MA==&mid=401383338&idx=1&sn=73009cce06d58656 ...

  8. yum.pid 已被锁定

      刚刚打开虚拟机,然后打算安装sharutils 工具在安装sharutils 工具的时候 终端提示 “/var/run/yum.pid 已被锁定,PID 为 1610 的另一个程序正在运行.” r ...

  9. 小白日记30:kali渗透测试之Web渗透-扫描工具-Skipfish

    WEB渗透-skipfish Skipfish是一个命令行模式,以C语言编写的积极的Web应用程序的安全性侦察工具,没有代理模式. 它准备了一个互动为目标的网站的站点地图进行一个递归爬网和基于字典的探 ...

  10. 12096 - The SetStack Computer UVA

    Background from Wikipedia: \Set theory is a branch of mathematics created principally by the German ...