简体   繁体   中英

How to read current project path in .properties file

I have abc.jks file under resources folder and i need to read that abc.jks file in test.properties file. How to read abc.jks file in test.properties file.

In application.properties (or how you name it) assuming you use maven and you execute your spring application in the default project you can refer to the file like:

my.file.name = ./src/main/resources/abs.jks

or if this is for test purpose only you can put in the test resources and refer like this:

my.file.name = ./src/test/resources/abs.jks

For me the best is to not be dependent on folder and always use classloader resource, but if you have to refer a path on the filesystem, from java code you can do this:

URL url = getClass().getClassLoader().getResource("abs.jks");
File file = Paths.get(url.toURI()).toFile().getAbsolutePath();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM