Write and read binary files in Android

前端 未结 3 599
执念已碎
执念已碎 2021-01-13 17:25

I created a custom object of type Task and I want to save it in a binary file in internal storage. Here is the class I created:



        
3条回答
  •  感动是毒
    2021-01-13 18:04

    From what I see, you are trying to dump the contents of the object into a file and then read it back. But the way you are doing it now is just writing all the data to the file without any structure, which is a terrible idea.

    I would recommend you try to implement the Serializable interface and then just use the writeObject() and readObject() methods.

    Alternatively, you could dump the data into an XML file or something that has some structure to it.

提交回复
热议问题