| | |
| | | response.setStatus(404); |
| | | } |
| | | } |
| | | @RequestMapping("/appVersion/downloadApp/{filename}/qrDownload") |
| | | public void qrDownload(@PathVariable String filename, HttpServletResponse response) { |
| | | try { |
| | | ClassPathResource pathResource = new ClassPathResource("appVersion/" + filename); |
| | | File file = pathResource.getFile(); |
| | | InputStream inputStream = pathResource.getInputStream(); |
| | | //输出文件 |
| | | InputStream fis = new BufferedInputStream(inputStream); |
| | | byte[] buffer = new byte[fis.available()]; |
| | | fis.read(buffer); |
| | | fis.close(); |
| | | response.reset(); |
| | | |
| | | //获取文件的名字再浏览器下载页面 |
| | | String name = file.getName(); |
| | | response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1")); |
| | | response.addHeader("Content-Length", "" + file.length()); |
| | | OutputStream out = new BufferedOutputStream(response.getOutputStream()); |
| | | response.setContentType("application/octet-stream"); |
| | | out.write(buffer); |
| | | out.flush(); |
| | | out.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | response.setStatus(404); |
| | | } |
| | | } |
| | | } |