The demo itself
// Find the ClassLoader that loaded us.
// Regard it as the One True Classloader for this app.
ClassLoader loader = this.getClass().getClassLoader();
// Use the loader's getResource() method to open the file.
InputStream is = loader.getResourceAsStream("widgets.properties");
if (is == null) {
System.err.println("Can't load properties file");
return;
}
// Create a Properties object
Properties p = new Properties();
// Load the properties file into the Properties object
try {
p.load(is);
} catch (IOException ex) {
System.err.println("Load failed: " + ex);
return;
}
// List it to confirm that we loaded it.
p.list(System.out);