流下载
发布日期: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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:成功则alert()
下一篇:ZIP操作

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月03日 02时43分12秒