Spring下载文件
来源:互联网 发布:nvidia caffe 编辑:程序博客网 时间:2024/05/28 09:31
转帖地址忘了
/**
* 下载文件
* @param response javax.servlet.http.HttpServletResponse
*/
@RequestMapping("/downloadFile")
public void downloadFile(HttpServletResponse response) {
String fileName = "D://test.txt";
File file = new File(fileName);
FileInputStream in = null;
InputStreamReader isr = null;
response.reset();
response.addHeader("Content-Disposition", "attachment;filename="
+ file.getName());
response.addHeader("Content-Length", "" + file.length());
response.setContentType("bin");
OutputStream toClient;
// 文件不存在时跳出
if (!file.exists()) {
return;
}
String s = null;
StringBuilder sb = new StringBuilder();
try {
in = new FileInputStream(file);
isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
while ((s = br.readLine()) != null) {
sb.append(s);
sb.append("/r/n"); // 换行符
}
isr.close();
in.close();
toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(sb.toString().getBytes());
toClient.flush();
toClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}
- Spring下载文件
- spring 直接下载文件
- Spring MVC 文件下载
- Spring mvc 文件下载
- spring mvc 文件下载
- Spring MVC下载文件
- Spring下载excel文件
- 使用spring文件下载
- spring mvc 文件下载
- Spring mvc 文件下载
- spring文件下载乱码
- extjs+spring 下载文件
- Spring MVC文件下载
- spring mvc下载文件
- Spring MVC 文件下载
- spring mvc文件下载
- Spring mvc 下载文件
- spring MVC文件下载
- Windows下搭建android开发环境
- Linux上运行Windows XP程序(wine1.3.x源码安装1)
- 当CAsyncSocket遇到多线程(转)
- python-变量,字符串 处理小技巧
- 经典SQL语句大全
- Spring下载文件
- android取得当前程序File与Cache路径!
- java 线程实例
- Ubuntu 10.04更新源
- SVN 服务器安装和配置
- spring hibernate集成
- 关于tomcat 404错误的总结
- asp.net(C#)服务器绝对路径与URL相对路径互转
- oracle的左连接右连接全连接