HttpURLConnection conn = null;
OutputStream outputStream = null;
InputStream inputStream = null;
try {
String path = r.getParameter("filename");
File fl = new File(path); URL url = new URL(path);
conn = (HttpURLConnection)url.openConnection();
inputStream = conn.getInputStream(); rp.reset();
rp.setHeader("Content-Disposition", "attachment;filename=\""+ fl.getName() + "\"");
rp.setContentType("application/octet-stream");
rp.setContentLength((int)conn.getContentLength());
rp.setHeader("Pragma", "No-cache");
rp.setHeader("Cache-Control", "No-cache");
rp.setDateHeader("Expires", 0); outputStream = new BufferedOutputStream(rp.getOutputStream());
byte[] buffer = new byte[4096];
int len = 0;
while((len = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
outputStream.flush();
} catch(Exception e){
e.printStackTrace();
} finally {
if(conn!=null){
conn.disconnect();
}
if(inputStream != null) {
inputStream.close();
}
if(outputStream != null) {
outputStream.close();
}
}

  

最新文章

  1. 利用poi导出Excel
  2. 大毕设-MATLAB-滤波器的实现
  3. SQL存储过程、视图
  4. js 添加广告
  5. java获取每个月的最后一天
  6. App引导页面源代码的实现
  7. BCS--使用SharePoint Designer创建外部内容类型
  8. google面试题,男孩男女比例?
  9. 关于Response.redirect和Response.End出现线程中止异常的处理
  10. log4j 日志脱敏处理 + java properties文件加载
  11. lambda高级进阶--组合函数
  12. C# WebSocket模拟发送接收
  13. 菜鸟学Java(二十三)——Java内存分析
  14. 代码编辑器之sublime text
  15. Set ARITHABORT Option设置为ON
  16. httpclient httpclient使用连接池
  17. Ubuntu 将应用程序固定到快速启动栏
  18. LoadRunner性能测试基础知识问答
  19. 快速上手Runtime(三)之方法交换
  20. 我的Android进阶之旅------>关于android:layout_weight属性的详细解析

热门文章

  1. Android上禁止屏幕旋转
  2. weui hd bd ft
  3. C++ vector和list的主要用法区别
  4. 【bzoj 1901】Zju2112 Dynamic Rankings
  5. Nginx 关闭日志生成文件
  6. NLTK1及NLP理论基础
  7. python日志1
  8. Oracle简单的序列应用
  9. Element Tabs 组件中使用 ve-histogram组件渲染不出来(已解决)
  10. cmd关闭被占用的端口命令及教程详解