Date Created: Mon 16-Feb-2009

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/



    Simple properties manager class to get Java properties from a Java property file.

    /*

    how to use the PropertiesManager class

    ProfileManager pm = new ProfileManager();
    PropertiesManager propman = new PropertiesManager();
    String profileBase = propman.getProperty("logview.properties","profiles.root");
    String logFolder = propman.getProperty("logview.properties","log.folder");

    */

    /*
    * Created on 09-Nov-2007
    *
    */
    package com.websphere.utils;

    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

    /**
    * @author Steven Charles Robinson - November - 2007
    *
    */
    public class PropertiesManager {

    /**
    *
    */
    public PropertiesManager() {
    super();
    // TODO Auto-generated constructor stub
    }

    public String getProperty(String propertyFile,String propertyName)
    {
    Properties props = null;
    // Get the properties file from the classpath
    try{
    props = getPropertiesFromClasspath(propertyFile);
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
    return props.getProperty(propertyName);

    }

    private Properties getPropertiesFromClasspath(String propFileName) throws IOException {
    Properties props = new Properties();
    InputStream inputStream = this.getClass().getResourceAsStream(propFileName);

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

    props.load(inputStream);

    return props;
    }

    }

    Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many leading brands around the world. Steve specialises in JEE, DevOps and Thought Leadership.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

Courses

Articles

WebSphere Categories

Other Categories