閱讀HashMap中我發現的代碼讀取一個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();
}
}
,但我沒有發現任何例如如何這個文件看起來像。你能用一個例子來解釋嗎?
這個文件不會是人類可讀的,因爲這將是二進制格式。 – Apurv
hm是否還有一些其他選項如何從文件 – hudi
中讀取hashMap您需要舉例說明您嘗試從中讀取散列表的文件的格式。 –