Classloader.getSystemResourceAsStream returns null

I am trying to load a properties file without using the actual file path. I have already done this in some other simple applications using:

InputStream inputStream = ClassLoader.getSystemResourceAsStream(PROPERTIES_FILE); props.load(inputStream); 

But this time it won’t work. For some reason, the input stream is zero. PROPERTIES_FILE - A constant defined as "app.properties". I tried to remove the .properties extension and got the same results.

Any ideas?

Thanks.

+6
java properties classloader
source share
2 answers

The PROPERTIES_FILE constant must include the package as well as the properties file (for example, "com / some / library / file.properties".

  final static String PROPS_FILE = "/com/some/library/file.props"; //The preceding "/" is dependendant on wheterh //you are going to be giving a relative or absolute location InputStream is = YourCurrentClass.class.getResourceAsStream(PROPS_FILE); 
+13
source share

When getSystemResourceAsStream returns null , it means that the resource was not found. Verify that the requested resource is indeed in the class path at the specified location.

0
source share

All Articles