file - Saving custom object to sdcard (Android) -
i'm exploring saving internally versus saving on sdcard. currently, i'm trying save custom object (dummytwice) on sdcard, so:
string root = (environment.getexternalstoragedirectory().tostring()); file dir = new file(root + pub_ext_dir); dir.mkdirs(); file file = new file(dir,file_name); try { dummytwice dt = new dummytwice(textenter.gettext().tostring()); fileoutputstream os = new fileoutputstream(file); objectoutputstream oos = new objectoutputstream(os); oos.writeobject(dt); oos.close(); os.close(); toast.maketext(v.getcontext(),"object saved",toast.length_short).show(); toast.maketext(v.getcontext(),file.getabsolutepath(), toast.length_long).show(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); }
execution stops at:
fileoutputstream os = new fileoutputstream(file);
catching exception:
filenotfoundexception e
what doing wrong? relevant constants:
private final static string pub_ext_dir = /data private final static string file_name = /obj.dat
you shouldn't write directly on sdcard, , should use
getexternalfilesdir(null)
instead of
environment.getexternalstoragedirectory()
getexternalfilesdir(null)
returns private path on sdcard activity
, /sdcard/android/data/package.your.app
Comments
Post a Comment