String fileName = "lenovo_data";
方式一:
ClassPathResource resource = new ClassPathResource("fileName");
File file = resource.getFile();
方式二:
String path = ResourceUtils.getURL("classpath:").toString();
File file = new File(path, fileName);
以上两种方式获取spring boot 项目资源文件下文件时,在 eclipse 环境中测试是可以获取到的,但是当打成jar包测试时,会抛出class path resource [xx] cannot be resolved to absolute file path because it does not reside 异常错误。