package com.propenum;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
public class PropertyUtil {
private final HashMap<String, String> properties;
private static PropertyUtil instance;
public static PropertyUtil getInstance() {
if (instance == null) {
instance = new PropertyUtil();
}
return instance;
}
private PropertyUtil() {
super();
properties = new HashMap<String, String>();
loadProperties();
}
private void loadProperties() {
Properties properties = new CustomProperties();
try {
properties.load(new FileInputStream("C:\\Users\\Shrikant\\eclipse-workspace\\EnumProject\\src\\com\\propenum\\validationcodes.properties"));
for (Entry<Object, Object> element : properties.entrySet()) {
properties.put(element.getKey().toString(), element.getValue().toString());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
public String getValueByCode(String code) {
return properties.get(code);
}
}
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Properties;
public class PropertyUtil {
private final HashMap<String, String> properties;
private static PropertyUtil instance;
public static PropertyUtil getInstance() {
if (instance == null) {
instance = new PropertyUtil();
}
return instance;
}
private PropertyUtil() {
super();
properties = new HashMap<String, String>();
loadProperties();
}
private void loadProperties() {
Properties properties = new CustomProperties();
try {
properties.load(new FileInputStream("C:\\Users\\Shrikant\\eclipse-workspace\\EnumProject\\src\\com\\propenum\\validationcodes.properties"));
for (Entry<Object, Object> element : properties.entrySet()) {
properties.put(element.getKey().toString(), element.getValue().toString());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
public String getValueByCode(String code) {
return properties.get(code);
}
}
complete example available on below link.