Property File

Still confused where you have to put a property files in your java project? This code for loads a property file located anywhere in your classpath.

public Properties getPropertiesFromClasspath(String propFileName)
  throws IOException {
  // loading xmlProfileGen.properties from the classpath
  Properties props = new Properties();
  InputStream inputStream = this.getClass().getClassLoader()
    .getResourceAsStream(propFileName);

  if (inputStream == null) {
    throw new FileNotFoundException("property file not found "+
      "in the classpath");
  }

  props.load(inputStream);
  return props;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s