參考:http://www.cnblogs.com/lihaoyang/p/7348293.html

 

@GetMapping("/{id}")
    public void download(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws Exception {

        try (InputStream inputStream = new FileInputStream(new File(folder, id + ".txt"));
                OutputStream outputStream = response.getOutputStream();) {
            
            response.setContentType("application/x-download");
            response.addHeader("Content-Disposition", "attachment;filename=test.txt");
            
            IOUtils.copy(inputStream, outputStream);
            outputStream.flush();
        } 

    }

}

 

posted on 2018-08-29 19:30  lshan  阅读(115)  评论(0编辑  收藏  举报