Save Map To File Java

[Solved] Save Map To File Java | Java - Code Explorer | yomemimo.com
Question : save map to file java

Answered by : ziv-sion

// Save map in file
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);
// Load the map
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());
}

Source : https://stackoverflow.com/questions/12747946/how-to-write-and-read-a-file-with-a-hashmap | Last Update : Fri, 04 Dec 20

Answers related to save map to file java

Code Explorer Popular Question For Java