I want to read a property file from a java class file which the both are packed together as a same jar.
Project Structure:
src
--->com
------->xyz
----------->Property(foldername)
-------------------------------------->abc.properties
----------->JavaClassFileFolder
-------------------------------------->a.java
In the above structure folder, i want to read a abc.properties
file from a.java
file. I tried below methods in a.java
file to read.
Method1:
InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/xyz/Property/abc.properties");
Properties prop = new Properties();
prop.load(in);
Result: Throws NPE at prop.load(in)
Method 2:
ClassLoader cl = Constants.class.getClassLoader();
Properties prop = new Properties();
prop .load(cl.getResourceAsStream("com/xyz/Property/abc.properties"));
Result: Throws NPE at prop.load(in)