android - save serialized object in phone memory -


here have data want store in phone memory , retrieve when necessary

here code:

 public void saveobject(person p){      try      {           fileoutputstream fos = openfileoutput("save_object.bin", context.mode_private);          objectoutputstream oos = new objectoutputstream(fos);           oos.writeobject(p); // write class 'object'         oos.flush(); // flush stream insure of information written 'save_object.bin'         oos.close();// close stream      }      catch(exception ex)      {         log.v("serialization save error : ",ex.getmessage());         ex.printstacktrace();      } }  public object loadserializedobject(file f) {     try     {          fileinputstream fin = openfileinput("save_object.bin");          object o = fin.read();         return o;      }     catch(exception ex)     {     log.v("serialization read error : ",ex.getmessage());         ex.printstacktrace();     }     return null; } 

using sdcard receiving error /mnt/sdcard/save_object.bin (permission denied)

retrieving by

person person1 = (person)loadserializedobject(getdir("save_object.bin",context.mode_private));//get serialized object sdcard , caste person class. 

class:

public class person implements serializable  {     string username="";     private static final long serialversionuid = 46543445;       public void setusername(string username)     {         this.username = username;     }          public string getusername()     {         return username;     }    } 

i have used

<uses-permission android:name="android.permission.write_external_storage" /> 

how store in phone memory @could me @thanks

since have not valid mountpoint /sdcard, have use application cache store object.

retrieve inputstream way:

fileinputstream fin = openfileinput("save_object.bin"); 

and fileoutputstream way:

 fileoutputstream fos = openfileoutput("save_object.bin", context.mode_private); 

to deserialize object change code way:

fileinputstream fin = openfileinput("save_object.bin");  objectinputstream ois = new objectinputstream(fin);  object o = ois.readobject(); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -