Assume standard maven setup. I have a file abc.conf in src/main/resources folder of my project. How do i get the absolute path to abc.conf in the code?
When you run your app, you are not using the resource file in your code folder(src/main/resources) but the ones in the target folder([yourProject]\\target as default) where you build to.The target folder path can be changed, it's not a absolute path.
So you can use a "absolute" path out of the content you run or use a "relative" path to the target folder.
Maven automatically sets the current working directory, then you can just use:
File resourcesDirectory = new File("src/main/resources/abc.conf");
System.out.println( resourcesDirectory.getAbsolutePath() ); //prints absolute path of your abc.conf
I hope it helps.
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.