public class PropertiesTool {
private Hashtable cachedFile = new Hashtable(); /**
* constructor
* @param fileName
*/
public PropertiesTool(String fileName){
getPropertiesFromClasspath(fileName);
}
public void getPropertiesFromClasspath(String file){
ResourceBundle rb = ResourceBundle.getBundle(file);
Enumeration en = rb.getKeys();
while(en.hasMoreElements()){
String key = String.valueOf(en.nextElement());
cachedFile.put(key,rb.getString(key));
}
}
public String getValueByKey(String key){
if (cachedFile!=null && cachedFile.size()!=0 && key !=null) {
return String.valueOf(cachedFile.get(key));
}
return "no data found";
}
public int getDataCount(){
if (cachedFile!=null) {
return cachedFile.size();
}else{
return 0;
}
}
public List getKeys(){
List result = new ArrayList();
Enumeration en = cachedFile.keys();
if (cachedFile!=null) {
while (en.hasMoreElements()) {
result.add(en.nextElement());
}
}
return result;
}
|