paradrop.xlsx 存在 src/main/resource/paradrop.xlsx@RequestMapping(value = "/downloadExcel") public void downloadExcel(HttpServletResponse response, HttpServletRequest request) throws IOException { String fileName = "paradrop.xlsx"; InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); //强制下载不打开 response.setContentType("application/binary;charset=ISO8859-1"); OutputStream out = response.getOutputStream(); //使用URLEncoder来防止文件名乱码或者读取错误 response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(fileName, "UTF-8")); int b = 0; byte[] buffer = new byte[1000000]; while (b != -1) { b = inputStream.read(buffer); if(b!=-1) out.write(buffer, 0, b); } inputStream.close(); out.close(); out.flush(); }