public void downloadLine(HttpServletResponse response) throws IOException { String fileName="保障任务直供及同母线线路.xlsx"; ClassPathResource classPathResource = new ClassPathResource("template/line.xlsx"); // 判断下载哪个excel // 初始化流 InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = classPathResource.getInputStream(); response.setContentType("application/x-msdownload"); outputStream = response.getOutputStream(); response.addHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes(), "iso-8859-1")); // 执行流操作 IoUtils.copy(inputStream, outputStream); } catch (IOException e) { log.error(e.getMessage()); } finally { // 关流 IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } }
java下载本地文件
最新推荐文章于 2024-05-17 16:03:49 发布