Is there any way of specifying the current directory in a java properties file?
ie something like:
fileLocation={currentDir}/fileName.txt
No. Properties files do not have any builtin macro facilities. You can programmatically get the currect directory of the user running the Java app through the user.dir system property .
我很确定它只是默认为当前目录,如果没有,你可以做到
fileLocation="./fileName.txt"
I don't know any direct solution for this problem. You can load the URL to the properties file and then load the filename from that file:
ClassLoader loader = YourClass.class.getClassLoader();
URL resourceURL =loader.getResource("check.properties");
String fileToLoad = resourceURL.getPath() + <fileNameFromPropertyFile>;
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.