The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
March 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Loading a properties file from a source relative to the classpath

Posted by John Lonergan on March 26, 2001 at 8:52 AM

// this example finds a properties file on the classpath and then loads it

String resourcePathRelativeToClasspath = "a/relative/directory/path/myprops.properties";

ClassLoader cl = ClassLoader.getSystemClassLoader();

URL url = cl.getResource(resourcePathRelativeToClasspath);
if (url == null)
{
// Could not find resource on classpath
}

InputStream rf = url.openStream();
if (rf == null)
{
// Failed opening stream for this resource
}

Properties props = new Properties();

props.load(rf);





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us