Java:存储hashmap的理想文件格式?

Ada*_*m_G 1 java file hashmap

我需要将一个hashmaps的arraylist保存到外部文件中.我可以使用任何期望的文本文件格式,因为程序设置为忽略文本文件(特别是任何带.txt扩展名的文件).哈希图非常简单,只是带有这些单词计数的单词.存储它的理想文件格式是什么?

Bal*_*usC 6

你可以用java.util.Properties.

Properties properties = new Properties();
properties.putAll(yourMap); // You could also just use Properties in first place.

try (OutputStream output = new FileOutputStream("/foo.properties")) {
    properties.store(output, null);
}
Run Code Online (Sandbox Code Playgroud)

你可以稍后阅读

Properties properties = new Properties();

try (InputStream input = new FileInputStream("/foo.properties")) {
    properties.load(input);
}

// ... (Properties implements Map, you could just treat it like a Map)
Run Code Online (Sandbox Code Playgroud)

也可以看看: