android - StreamCorruptedException and ObjectInputStream|FileInputStream -
after creating backup of shared preference xml
file(programmatically) , saving external storage, created method restoring it, reading data objectinputstream
, fileinputstream
xml file, , put data in app's shared preference.
this how i'm restoring data:
public void restorefav(context context) { file src = new file(storagepath+prefs_name+".xml"); objectinputstream input = null; try { input = new objectinputstream(new fileinputstream(src)); sharedpreferences.editor prefedit = context.getsharedpreferences(prefs_name, context.mode_private).edit(); log.d("pref restore prefedit",prefedit.tostring()); prefedit.clear(); log.d("pref restore prefedit",prefedit.tostring()); map<string, ?> entries = (map<string, ?>) input.readobject(); log.d("pref restore entries",entries.tostring()); (map.entry<string, ?> entry : entries.entryset()) { object v = entry.getvalue(); log.d("pref restore object v",v.tostring()); string key = entry.getkey(); log.d("pref restore string key", key); prefedit.putstring(key, ((string) v)); } prefedit.apply(); } catch (classnotfoundexception | ioexception e) { e.printstacktrace(); } { try { if (input != null) { input.close(); } } catch (ioexception ex) { ex.printstacktrace(); } } }
but i'm getting streamcorruptedexception
exception.
08-20 18:42:44.228: w/system.err(28802): java.io.streamcorruptedexception 08-20 18:42:44.238: w/system.err(28802): @ java.io.objectinputstream.readstreamheader(objectinputstream.java:2115) 08-20 18:42:44.238: w/system.err(28802): @ java.io.objectinputstream.<init>(objectinputstream.java:372)
what doing wrong!?
Comments
Post a Comment