SpringBoot在window和linux都可以获取resource路径的方法

// 获取项目根路径
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());

这个再Windows下是可以的,但是在Linux (centos7)下是不行的,正确的获取方法:

Resource resource = new ClassPathResource("");
System.out.println(resource.getFile().getAbsolutePath());

 

原文地址:https://www.cnblogs.com/javalinux/p/15015716.html