how to store hashmap data to file java code example
Example: save map to file java
Map<String, String> map = new HashMap<String, String>();
Properties properties = new Properties();
for (Map.Entry<String,String> entry : map.entrySet()) {
properties.put(entry.getKey(), entry.getValue());
}
properties.store(new FileOutputStream("data.properties"), null);
Map<String, String> map_from_file = new HashMap<String, String>();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));
for (String key : properties.stringPropertyNames()) {
map_from_file.put(key, properties.get(key).toString());
}