I need to read a properties files that's buried in my package structure in com.al.common.email.templates
.
I've tried everything and I can't figure it out.
In the end, my code will be running in a servlet container, but I don't want to depend on the container for anything. I write JUnit test cases and it needs to work in both.
The following two cases relate to loading a properties file from an example class named
TestLoadProperties
.Case 1: Loading the properties file using
ClassLoader
In this case the properties file must be in the
root/src
directory for successful loading.Case 2: Loading the properties file without using
ClassLoader
In this case the properties file must be in the same directory as the
TestLoadProperties.class
file for successful loading.Note:
TestLoadProperties.java
andTestLoadProperties.class
are two different files. The former,.java
file, is usually found in a project'ssrc/
directory, while the latter,.class
file, is usually found in itsbin/
directory.use the below code please :