KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > util > PropertiesLoader


1 package org.objectweb.rentacar.util;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.util.Properties JavaDoc;
6
7 public class PropertiesLoader {
8
9     /**
10      * Returns the value of a property found in the specified file
11      * @param inputFile The path to the properties file
12      * @param property The name of the property to be returned
13      * @return The value of the property
14      * @throws PropertyLoadingException
15      */

16     public static String JavaDoc getProperty(String JavaDoc inputFile, String JavaDoc property) throws PropertyLoadingException{
17         
18             Properties JavaDoc prop = new Properties JavaDoc();
19             try{
20                 if (new File JavaDoc(inputFile).exists()){
21                     prop.load(new FileInputStream JavaDoc(inputFile));
22                 }
23                 else {
24                     prop.load(PropertiesLoader.class.getClassLoader().getResourceAsStream(inputFile));
25                 }
26             }
27             catch (Exception JavaDoc e){
28                 throw new PropertyLoadingException("Error while loading the file",e);
29             }
30             return (String JavaDoc)prop.get(property);
31     }
32 }
33
Popular Tags