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