📜  将地图保存到文件 java 代码示例

📅  最后修改于: 2022-03-11 14:52:20.785000             🧑  作者: Mango

代码示例1
// 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 the map
Map map_from_file = new HashMap();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));

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