Write ArrayList of custom objects to File

前端 未结 2 582
情歌与酒
情歌与酒 2021-01-23 08:02

I have an ArrayList which contains custom Service objects. I want to write the whole ArrayList to a File and be able to read it afterwards.

I tried Gson for that, but it

2条回答
  •  长发绾君心
    2021-01-23 08:13

    I would recommend using serialization for such an operation. You can implement Java's Serializable interface and you are then able to deflate your objects into a .ser file and then inflate them back from that very file to call the methods you need from them.

    Here is a nice tutorial regarding Serialization - http://www.tutorialspoint.com/java/java_serialization.htm

提交回复
热议问题