In my package com.foo.bar, I have two files, Config.java and config.properties. At the top of Config, I'm trying to read config.properties and set some internal variables:
public class Config
{
public static String foo;
public static String bar;
static
{
try
{
System.out.println("Loading");
InputStream is = Config.class.getClassLoader().getResourceAsStream("config.properties");
System.out.println("stream: " + is );
Properties props = new Properties();
props.load(is);
foo = props.getProperty("foo");
bar = props.getProperty("bar");
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
//snip...
}
Despite config.properties file existing in the same package, I get this output:
Loading
stream: null
And then a NullPointerException on the line props.load(is).
What am I doing wrong? From some googling, it seems that I'm using the correct method for reading the file. Is it because I'm doing this in a static block, that I'm having this issue?