String root= ServletActionContext.getServletContext().getRealPath(File.separator).replace("\\", File.separator);
String fileName = "download.text";
File file = new File(root + fileName);
in = new FileInputStream(file);
// 设置响应正文的MIME类型
response.setContentType("Content-Disposition;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;" + " filename=\""+ URLEncoder.encode(fileName, "UTF-8") + "\"");
// 把本地文件发送给客户端
out = response.getOutputStream();
int byteRead = 0;
byte[] buffer = new byte[512];
while ((byteRead = in.read(buffer)) != -1)
{
  out.write(buffer, 0, byteRead);
}
in.close();
out.close();

最新文章

  1. 查看死锁 的存储过程 ,工具存储过程 sp_who_lock
  2. 2014年4月份第2周51Aspx源码发布详情
  3. TF Boys (TensorFlow Boys ) 养成记(六)
  4. LINUX 用户’nobody’
  5. javascript绑定事件
  6. arduino pro mini不能下载
  7. 读书笔记 effective c++ Item 27 尽量少使用转型(casting)
  8. 利用Hive分析nginx日志
  9. 实现iframe高度自适应
  10. SpringMVC使用StandardServletMultipartResolver上传文件
  11. 基于IPv6的数据包分析
  12. Dom 兼容处理
  13. ubuntu 16.04下使用 python pip的安装问题。
  14. layui table 前台数字格式保留两位小数,不足补0(mysql 数据库)
  15. Javascript 对象创建多种方式 原型链
  16. (转)OpenGL ES编程入门资源集合
  17. (转)Spring开启Annotation<context:annotation-config> 和 <context:component-scan>诠释及区别
  18. AWS系列-复制AMI到其他区域
  19. LeetCode——Maximum Product of Three Numbers
  20. [freemarker篇]03.如何处理空值

热门文章

  1. 一个基于typelist的typemap
  2. 被称为“开发者神器”的GitHub,到底该怎么用?
  3. erlang遍历目录
  4. Spring Boot使用单元测试
  5. 在Docker中监控Java应用程序的5个方法
  6. startup.bat 一闪而过解决方案
  7. Java虚拟机------JVM介绍
  8. linux中 bashrc文件的alias添加快捷命令
  9. 7-安装Spark
  10. [UnityAPI]SerializedObject类 & SerializedProperty类