这是将哈希表写入.txt 文件的代码!
public static void save(String filename, Map<String, String> hashtable) throws IOException {
Properties prop = new Properties();
prop.putAll(hashtable);
FileOutputStream fos = new FileOutputStream(filename);
try {
prop.store(fos, prop);
} finally {
fos.close();
}
}
我们如何从该文件中取回哈希表? 谢谢
最佳答案
以同样丑陋的方式:
@SuppressWarnings("unchecked")
public static Map<String, String> load(String filename) throws IOException {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(filename);
try {
prop.load(fis);
} finally {
fis.close();
}
return (Map) prop;
}
关于java - 如何使用属性从 .txt 文件取回 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2822147/