文件下载
/**
* 检索列表中下载附件
* 传入参数:@param uploadFile
* 传入参数:@param request
* 返回类型:void
*/
@RequestMAPPing(value = "/downloadFile")
public void downloadFile(UploadFile uploadFile,HttpServletRequest request, HttpServletresponse response) {
BufferedInputStream in = null;
Bufferedoutputstream out = null;
fileinputstream fis=null;
try {
/*根据id单条查询*/
uploadFile = allSearchService.queryFileInformationById(uploadFile);
response.setcontenttype("text/html;charset=UTF-8");
//String rootpath = request.getsession().getServletcontext().getrealpath("/");
String rootpath=SysParaMinits.ARRANGE_FILE_PATH;//配置文件中指定下载文件路径。例D:\files
File f = new File(rootpath + File.separator + uploadFile.getFilepath());
response.reset();
response.setContentType("application/x-excel");
response.setCharacterEncoding("UTF-8");
response.setheader("content-Disposition", "attachment; filename="
+ new String(uploadFile.getFilename().getBytes("gbk"),"iso-8859-1"));
response.setHeader("Content-Length",String.valueOf(f.length()));
fis=new FileInputStream(f);
in = new BufferedInputStream(fis);
out = new BufferedOutputStream(response.getOutputStream());
byte[] data = new byte[1024];
int len = 0;
while (-1 != (len=in.read(data, 0, data.length))) {
out.write(data, 0, len);
}
} catch (Exception e) {
e.printstacktrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
}
相关阅读
Java采用Http方式实现大文件下载 java实现大文件下载,基于http方式,控件神马的就不说了。 思路:下载文件无非要读取文件然后写文
一年前,我发表过一篇文章《Word产品需求文档,已经过时了》,可能有一些关注我的朋友看过。而经过一年时间,我在以前的版本上又进行了一
解决win10安装net framework 3.5失败问题(附带sxs文件
win10安装net framework 3.5失败原因无非程序功能开启失败,解决办法如下: 一、从win10安装包目录中拷贝sxs文件到E盘根目录下。 (1)wi
一、前台通过a标签打开接口,传入文件id<a href="/cdc/announcement/downloadFile/1">下载</a> 二、后台接收id,查找对应文件,进行下
public HttpServletResponse download(String path, HttpServletResponse response) { try { // path是指欲