In my previous post I showed how to serialize an object and save it in sdcard in a file and retrieve it.

Pull out the file from the sdcard and then create a folder named “raw” inside the “res” folder and copy it.

Serialization pull out file.
This example shows how to retreive it when it is in the res/raw folder.

Here is the code that does this.

 public void readFromResources(){
         	InputStream is = getResources().openRawResource(R.raw.save_object);
         	ObjectInputStream ois = new ObjectInputStream(is);
         	Person person = (Person)ois.readObject();
         	Log.v("Person : >> Name : ",person.getName() + ", Address : " + person.getAddress() + ", Number : " + person.getNumber());
         catch(Exception ex)
        	 Log.v("Serialization Error >> ",ex.getMessage());

You are done. Go on and run it.
Check the Logcat for the results.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.