Skip to content Skip to sidebar Skip to footer

How To Serialize And Deserialize In Android?

my mainActivity has a ListView which should display my CustomList: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputS

Solution 1:

You can't write into the res directory (that's read-only), you have to write to somewhere else, e.g. to the cache directory (if it's only temporary; use context.getCacheDir() to get it's location) or to some permanent space (e.g. context.getFilesDir()).

You can get the file location like this, what you can pass to the FileOutputStream's or the FileInputStream's constructor:

Filefile=newFile(context.getFilesDir(), "data.dat");

You may also have to request permission to write to external storage if you choose so.

Read more about storing files in Android here: http://developer.android.com/training/basics/data-storage/files.html

Post a Comment for "How To Serialize And Deserialize In Android?"