admin管理员组文章数量:1533913
一、声明
注意参数要有HttpServletResponse response并设置参数
response.setContentType("application/application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment;filename=" + fileName);
@RequestMapping(value = "downloadZip", method = RequestMethod.GET)
public void downloadZip(HttpServletResponse response,String id) throws Exception {
String fileName=workCardPhotoFileService.downloadZipFile(id);
if (StringUtils.isNotEmpty(fileName)){
response.setContentType("application/application/vnd.ms-excel");
response.setHeader("Content-disposition",
"attachment;filename=" + fileName);
download(response.getOutputStream(),fileName);
}
}
public void download(OutputStream os, String fileName) throws IOException {
//获取服务器文件
File file = new File("/Users/Desktop/download/workcardphoto/"+fileName);
InputStream ins = new FileInputStream(file);
byte[] b = new byte[1024];
int len;
while((len = ins.read(b)) > 0){
os.write(b,0,len);
}
os.flush();
os.close();
ins.close();
}
结束~感谢观看
版权声明:本文标题:java 获取服务器文件,直接下载到浏览器 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726114547a1055961.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论