Close

Load Properties from classpath

[Updated: Dec 7, 2016, Created: Feb 13, 2016]

Java 

Use ClassLoader.getResourceAsStream(String resourceName) to get input stream of a specified resource.

Then use Properties.load(InputStream inStream)

JDK 1.7

public static Properties loadProperties (String fileName) throws IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties props = new Properties();
try (InputStream resourceStream = loader.getResourceAsStream(fileName)) {
props.load(resourceStream);
return props;
}
}



See Also