I have a class that loads its properties file using class.getResourceAsStream(props.properties). The properties file is in the same package as the class itself, yet it is now returning null rather than the object. I am frazzled because this works fine on an original computer, yet fails on a different computer. I copied the entire directory structure over from the old to the to new. I’m using Netbeans 7.2.1 on both computers. I’m sure its got to be a classpath setting or SOMETHING but I cant find any differences between the two environments whatsoever. Here’s sample code:
package Cab;
import java.util.*;
import java.lang.reflect.*;
import java.io.*;
public class CabTest{
public static void main(String[] args)
{
Properties l_Prop = new Properties();
InputStream l_IS;
try
{
l_IS = CabTest.class.getResourceAsStream("props.properties");
l_Prop.load(l_IS);
}
catch(IOException l_Exc)
{
System.out.println(l_Exc);
}
}
}
This says that if the .class file is in package “foo.bar.baz.props.properties”, then that’s the path you ought to give to the classloader:
Your way will work only if it’s at the root of the CLASSPATH.