Save map in file java

Save map in file

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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);
</string,string></string,></string,>
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); </string,string></string,></string,>
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Map<string, string=""> mapFromFile = new HashMap<string, string="">();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));
for (String key : properties.stringPropertyNames()) {
mapFromFile.put(key, properties.get(key).toString());
}
</string,></string,>
Map<string, string=""> mapFromFile = new HashMap<string, string="">(); Properties properties = new Properties(); properties.load(new FileInputStream("data.properties")); for (String key : properties.stringPropertyNames()) { mapFromFile.put(key, properties.get(key).toString()); } </string,></string,>
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());
}