DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Read A Properties File Inside Jar File

  • submit to reddit
String sConfigFile = "config/";
InputStream in = mailSender.class.getClassLoader().getResourceAsStream(sConfigFile);
if (in == null) {
	//File not found! (Manage the problem)
Properties props = new java.util.Properties();


Snippets Manager replied on Mon, 2012/05/07 - 1:15pm

Corrected. Thanks Llucifer

Snippets Manager replied on Mon, 2012/05/07 - 1:15pm

Beware that ClassLoader#getResourceAsStream returns null if the resource is not found. The will throw an ugly NPE at props.load(in).