ClassLoader cl = ClassLoader.getSystemClassLoader();
if (cl != null) {
URL url = cl.getResource(CONF_PROPERTIES);
if (null == url) {
url = cl.getResource("/" + CONF_PROPERTIES);
}
if (null != url) {
try {
InputStream in = url.openStream();
props = new Properties();
props.load(in);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Tuesday, January 22, 2013
How to load resource from classpath in java
How to load resource from anywhere in classpath in java.
Subscribe to:
Post Comments (Atom)
In case we need only the resource path in the hard disk:
ReplyDeleteString path = ClassLoader.getSystemClassLoader().getResource(".").getPath();