博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 下载文件
阅读量:4325 次
发布时间:2019-06-06

本文共 1142 字,大约阅读时间需要 3 分钟。

public class TemplateUtil {
public void downloadTemplate(HttpServletResponse response) throws Exception{
InputStream inputStream =null ; OutputStream outputStream = null; inputStream = this.getClass().getResourceAsStream("/files/template.xlsx"); if (inputStream == null){
throw new Exception("未找到模板文件"); } response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setCharacterEncoding("UTF-8"); response.setHeader("content-disposition","attachment;filename=" + "模板.xlsx"); try{
outputStream = response.getOutputStream(); byte[] readBytes = new byte[1024]; int read = 0; while ((read = inputStream.read(readBytes)) != -1){
outputStream.write(readBytes,0,read); outputStream.flush(); } } catch (Exception e){
// do something } finally {
if (inputStream != null){
inputStream.close(); } if (outputStream != null){
outputStream.close(); } } } }

转载于:https://www.cnblogs.com/phoenix-wings/p/10119593.html

你可能感兴趣的文章
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
PCRE demo【转】
查看>>
矩阵的SVD分解
查看>>
性能优化之数据库优化
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
tomcat 7服务器跨域问题解决
查看>>
前台实现ajax 需注意的地方
查看>>
Jenkins安装配置
查看>>
个人工作总结05(第二阶段)
查看>>
Java clone() 浅拷贝 深拷贝
查看>>
深入理解Java虚拟机&运行时数据区
查看>>
02-环境搭建
查看>>
spring第二冲刺阶段第七天
查看>>