How to read and write a HashMap to a file?

前端 未结 5 427
南笙
南笙 2020-12-09 04:13

I have the following HashMap:

HashMap fileObj = new HashMap();

ArrayList cols         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 04:38

    Your first line:

    HashMap fileObj = new HashMap();
    

    gave me pause, as the values are not guaranteed to be Serializable and thus may not be written out correctly. You should really define the object as a HashMap (or if you prefer, simpy Map).

    I would also consider serializing the Map in a simple text format such as JSON since you are doing a simple String -> List mapping.

提交回复
热议问题