Skip to content Skip to sidebar Skip to footer

How To Deserialize A File Back To The Original Class Object

I created a class and I periodically save objects of this class to internal storage using Serializable. When I want to retrieve these objects, I use this approach: for(File i: getF

Solution 1:

Even when I use listFiles() to get all the files in the directory, they are represented as files, not Card Objects.

That's because they are files, not objects.


Solution 2:

The mistake I made was failing to cast my newly gotten object to my intended class.

Changing

SingleWallet theObjectWeWant = ois.readObject();

to

SingleWallet theObjectWeWant = (SingleWallet) ois.readObject();

made the difference.

Basically, I should have casted from object to SingleWallet.

I hope this helps someone out there.


Post a Comment for "How To Deserialize A File Back To The Original Class Object"