Reputation: 359
My java class is residing in the folder /webserver/tomcat-instance/webapps/shop/WEB-INF/classes/com/mobile/commons
but the actual property file is residing in the location
/webserver/tomcat-instance/webapps/shop/WEB-INF/classes/resources
directory. Now in my java file i put the relative path as /WEB-INF/classes/resources/prop.properties
to read the intended file but every time i'm getting the FileNotFound Exception.
Please help me resolving this issue. What should i use as a relative path as i don't want to use the absolute path.
Thanks, Sourav
Upvotes: 0
Views: 855
Reputation: 240900
Try reading it with
this.getClass().getClassLoader().getResourceAsStream("resources/prop.properties");
Update:
URL resource = classLoader.getResource("resources/prop.properties");
File file = new File(resource.toURI());
FileInputStream input = new FileInputStream(file);
Upvotes: 1
Reputation: 462
it's better to use
Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/prop.properties")
Upvotes: 1