首页 > 编程语言 > 详细

java流下载

时间:2015-03-09 14:17:42      阅读:370      评论:0      收藏:0      [点我收藏+]

 

 

@RequestMapping("/pluginDownload")
    public void pluginDownload(HttpServletResponse response) throws FileNotFoundException {
        // 下载本地文件
        String fileName = "plugin.rar";
        // 读到流中
        InputStream inStream = new FileInputStream("d:/up_pipegis/plugin/plugin.rar");
        // 设置输出的格式
        response.reset();
        response.setContentType("bin");
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        // 循环取出流中的数据
        byte[] b = new byte[128];
        int len;
        try {
            while ((len = inStream.read(b)) > 0)
                response.getOutputStream().write(b, 0, len);
            inStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

java流下载

原文:http://www.cnblogs.com/vvonline/p/4323327.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!