public static void main(String[] args)throws IOException {
ClassPathResource classPathResource = new ClassPathResource("1.txt");
Resource resource = new ClassPathResource("1.txt");
//获1.txt的取相对路径
String classPathStr = classPathResource .getFile().getPath();
System.out.println(classPathStr);
String path = resource.getFile().getPath();
System.out.println(path);
}
使用的jar分别是:
org.springframework.core.io.ClassPathResource,
org.springframework.core.io.Resource