我找到了从文件(在磁盘上)读取 hashMap 的代码:
public HashMap<String, Integer> load(String path)
{
try
{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
Object result = ois.readObject();
//you can feel free to cast result to HashMap<String, Integer> if you know that only a HashMap is stored in the file
return (HashMap<String, Integer>)result;
}
catch(Exception e)
{
e.printStackTrace();
}
}
但我没有找到任何示例该文件的外观如何。你能用一个例子来解释一下吗?