springboot 读取Jar 类路径下的文件

        Resource resource = new DefaultResourceLoader().getResource("classpath:download/WORKER_OVERTIME_RECORD.xlsx");
        response.setContentType("application/x-msdownload;");
        response.setHeader("Content-disposition", "attachment; filename=WORKER_OVERTIME_RECORD.xlsx");
//        response.setHeader("Content-Length", String.valueOf(resource.get));
        FileCopyUtils.copy(resource.getInputStream(),response.getOutputStream());

只能用inputstream, 不能是file

你可能感兴趣的:(springboot 读取Jar 类路径下的文件)