2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Loading properties file available inside the package using Java

I kept my properties file in a package like com.test.property . And now I want to load and read the keys from it.

I know after reading this a lot of questions will come why not I can keep it in java class path but as my project requirement 

bound to keep it in any of the package.

I follow the normal way to load the properties file but fail.Please suggest!


Below code snippet will help you to load and read the properties file available in a package.

        Properties prop = new Properties(); 

        InputStream inStream = ReadPropertyFileInPackage.class.




Please Note : ReadPropertyFileInPackage.class is nothing but your current class name from where you can going to use the above code to load your properties file.And getResourceAsStream("/com/test/property/kodetalk.properties"); will contain the properties file name with complete package name.

Answer is