Save map in file java

Save map in file

Map map = new HashMap();
Properties properties = new Properties();

for (Map.Entry entry : map.entrySet()) {
    properties.put(entry.getKey(), entry.getValue());
}

properties.store(new FileOutputStream("data.properties"), null);

Load map from file

Map mapFromFile = new HashMap();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));

for (String key : properties.stringPropertyNames()) {
   mapFromFile.put(key, properties.get(key).toString());
}