如何访问保存在资源文件夹下的资源文件
How to access the resource files that are kept under resources folder
如何获取下图文件夹下的文件(cacerts.pem,client.pem,client-key.pem)的绝对路径
这是在eclipse和gradle环境下
我通常使用作弊来到达那里!
Paths.get(SomeClass.class.getClassLoader().getResource("").toURI());
构建 java 代码后,所有资源都将转到其目标输出,例如,您会得到类似 target/io/geocloud/management/client/* .
的内容
对于你的具体问题,我会稍微修改一下代码,然后做一些类似的事情
Paths.get(SomeClass.class.getClassLoader().getResource("io/geocloud/management/client/ca/cacerts.pem").toURI()).toAbsolutePath().toString();
使用Spring:
Resource resource = new ClassPathResource("file/location/cert.pem");
File file = resource.getFile();
如何获取下图文件夹下的文件(cacerts.pem,client.pem,client-key.pem)的绝对路径
这是在eclipse和gradle环境下
我通常使用作弊来到达那里!
Paths.get(SomeClass.class.getClassLoader().getResource("").toURI());
构建 java 代码后,所有资源都将转到其目标输出,例如,您会得到类似 target/io/geocloud/management/client/* .
的内容对于你的具体问题,我会稍微修改一下代码,然后做一些类似的事情
Paths.get(SomeClass.class.getClassLoader().getResource("io/geocloud/management/client/ca/cacerts.pem").toURI()).toAbsolutePath().toString();
使用Spring:
Resource resource = new ClassPathResource("file/location/cert.pem");
File file = resource.getFile();