为了账号安全,请及时绑定邮箱和手机立即绑定

当点击下载的时候文件,不是我们平时见到的那种,弹出下载提示框,选择保存位置,而是直接跳转到新的页面,页面显示的是文件的乱码。

当点击下载的时候文件,不是我们平时见到的那种,弹出下载提示框,选择保存位置,而是直接跳转到新的页面,页面显示的是文件的乱码。

NeverGiveUp7 2015-06-23 19:39:11
URL:reportMainDodyUrl【例如:http://down10.zol.com.cn/skycndownernew/keaibizhi83_346188.exe】 求大神看一下! private void downLoadNet(String reportMainDodyUrl) throws IOException {        int last = reportMainDodyUrl.lastIndexOf("/");        String filename = reportMainDodyUrl.substring(last+1, reportMainDodyUrl.length());                URL url = new URL(reportMainDodyUrl);        InputStream inStream = null;        ServletOutputStream ouputStream = null;        try {            URLConnection conn = url.openConnection();            inStream = conn.getInputStream();                       response.reset();            response.setContentType("application/octet-stream");            response.addHeader("Content-Disposition", "attachment;filename=" + filename);            ouputStream = response.getOutputStream();                        byte[] buffer = new byte[1204];            int byteread = 0;            while ((byteread = inStream.read(buffer)) != -1) {            ouputStream.flush();                ouputStream.write(buffer, 0, byteread);            }        } catch (Exception e) {        logger.error("File download failed!", e);        } finally {        if (inStream != null){        inStream.close();        }        if (ouputStream != null) {        ouputStream.flush();        ouputStream.close();        }        }    }
查看完整描述

1 回答

  • 1 回答
  • 1 关注
  • 1933 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信