java流下载

 

 

@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();
        }
    }

 

posted @ 2015-03-09 13:13  vv_online  阅读(106)  评论(0编辑  收藏  举报