get请求下载文件

    @GetMapping("app")
    public void app(HttpServletResponse response) throws IOException {
        ServletOutputStream out = null;
        ClassPathResource classPathResource = new ClassPathResource("document/scyf.apk");
        InputStream in = classPathResource.getInputStream();
            response.setContentType("application/octet-stream");
            response.addHeader("Content-Disposition", "attachment; filename=\"scyf.apk\"");
            out = response.getOutputStream();
            int len = 0;
            byte[] buffer = new byte[1024 * 10];
            while ((len = in.read(buffer)) != -1) {
                out.write(buffer, 0, len);
            }
            out.flush();
            out.close();
            in.close();
    }

 

posted @ 2022-06-29 15:49  _Lawrence  阅读(881)  评论(0编辑  收藏  举报