I am unable to write into my properties file for not sure why as not encountering any kind of error or something. I have tried debugging but nothing found. Here is my PropertiesUtil
class.
public class PropertyUtil {
public static PropertyUtil prop;
private Properties properties;
public PropertyUtil() {
properties = new Properties();
}
public static synchronized PropertyUtil getInstance() {
if (prop == null) {
prop = new PropertyUtil();
}
return prop;
}
public void load(String fileName) throws IOException {
InputStream input = null;
input = getClass().getClassLoader().getResourceAsStream(fileName);
properties.load(input);
}
public void load(File file) throws IOException {
InputStream input = new FileInputStream(file);
properties.load(input);
}
public void clear() {
properties.clear();
}
public String getValue(String key) {
return properties.getProperty(key).trim();
}
public void setValue(String key, String value) {
properties.setProperty(key, value);
}
public HashMap<String, String> propertiesMap() {
HashMap<String, String> map = new HashMap<String, String>((Map) properties);
return map;
}
public void propertytonull() {
prop = null;
}
}
And this is how I am trying to write into the properties file in class.
prop.setValue("RequestId",res_RequestId);
prop.setValue("Id",res_Id);
RequestId and Id
is key already exists into my .properties file.
How to write values in a properties file through java code is not the answer to my question as answer in that file, removes all the data from the properties file and saves what you pass. Where as My question is verify specific to particular key.