流下载
发布日期:2021-09-30 18:11:13
浏览次数:23
分类:技术文章
本文共 1885 字,大约阅读时间需要 6 分钟。
private ActionForward doExportPrefixData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String fileName=request.getParameter("fileName"); //页面传来的文件名 String filePath=ServerInfo.getDownloadPath()+fileName;//路径+文件名 try { InputStream in=new FileInputStream(new File(filePath)); BufferedInputStream bfin=new BufferedInputStream(in); response.setBufferSize(5*1024*1024);//5M大小 response.setContentType("APPLICATION/OCTET-STREAM"); response.setHeader("Content-Disposition","attachment;filename="+fileName);//设置文件头 OutputStream out=response.getOutputStream(); BufferedOutputStream bfout=new BufferedOutputStream(out); int len=0; byte[] b=new byte[1024*1024]; while((len=bfin.read(b))!=-1) { bfout.write(b, 0, len); bfout.flush(); } bfout.close(); out.close(); bfin.close(); in.close(); } catch (FileNotFoundException e) { showInfoDialog(response,"文件没找到"); } catch (IOException e) { showInfoDialog(response,"文件读取失败"); } return null; } /** * * 方法描述:公用的弹出提示框 * @param response * @param msg 要提示的消息 */ private void showInfoDialog(HttpServletResponse response,String msg) { try { response.setContentType("text/html;charset=gb2312"); PrintWriter pw=response.getWriter(); pw.print(""); pw.flush(); pw.close(); } catch (IOException e1) { e1.printStackTrace(); } }
转载地址:https://blog.csdn.net/iteye_10361/article/details/81688592 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月03日 02时43分12秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
水平切分与垂直切分
2019-04-27
MySQL引擎
2019-04-27
MySQL下的NoSQL解决方案HandlerSocket
2019-04-27
Apache服务器下使用 ab 命令进行压力测试
2019-04-27
查看Firefox中的缓存
2019-04-27
http header头设置反向代理不缓存
2019-04-27
配置MySQL主从复制
2019-04-27
CI框架如何删除地址栏的 index.php
2019-04-27
expires与etag控制页面缓存的优先级
2019-04-27
取消掉Transfer-Encoding:chunked
2019-04-27
HTTP协议中的Tranfer-Encoding:chunked编码解析
2019-04-27
JavaScript面向对象编程
2019-04-27
在Javascript中使用面向对象的编程
2019-04-27
PHP Webservice的发布与调用
2019-04-27
php反射类 ReflectionClass
2019-04-27
为 PHP 应用提速、提速、再提速
2019-04-27
Linux下gedit显示行号
2019-04-27
《Advanced PHP Programming》读书笔记
2019-04-27
让我们谈谈RAID
2019-04-27
jQuery日期选择器插件date-input
2019-04-27