1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class PropertiesService {
Properties properties = new Properties();
public PropertiesService() {
super();
}
public Properties loadProperties(String propertiesFileLocation) throws FileNotFoundException, IOException {
Properties props = new Properties();
props.load(new FileInputStream(propertiesFileLocation));
return props;
}
public Properties updateProperties(Properties propsInput,Properties props) {
Iterator it = props.keySet().iterator();
while (it.hasNext()) {
String propertyName =(String)it.next();
String propertyValue =props.getProperty(propertyName);
propsInput.put(propertyName, propertyValue);
}
return propsInput;
}
public void save(Properties props, String location) throws IOException
{
PrintWriter printer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(location)));
for (Iterator it = props.entrySet().iterator(); it.hasNext();)
{
Map.Entry entry = (Map.Entry) it.next();
printer.println(entry.getKey() + "=" + entry.getValue()); ;
}
printer.close();
}
} |