Many seem to have this problem and like me they give up after sometime. Here is what I had to get this working. The trick here to use relative path for file lookup is to make sure your classes folder contains resources files along with src files. Here is what I ended up doing.
1) If you are using eclipse make sure you proper .classpath setting present and do PROJECT CLEAN to see the resources files get generated under /classes. Notice the classpath-entries below for resource files place under src/main/resource
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry kind="var" path="M2_REPO/javax/mail/mail/1.4.4/mail-1.4.4.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2) If you are using maven as well make sure you configure your pom.xml as per the https://maven.apache.org/guides/introduction/introduction-to-the-pom.html and do mvn clean install to see the files under target/classes
3) Once you have got the resource files under /classes the next thing to do in java is the following. Don't forget to have the forward slash.
try {
properties.load(getClass().getResourceAsStream("/mail-config.properties"));
} catch (IOException e) {
e.printStackTrace();
}
I could have added some images but did not have points. :)