Android store bitmap in internal directory -
i'm trying save file in internal memory android application can't manage correctly!
here's method store bitmap:
private void storebitmapinmemory(string id) throws ioexception { url newurl = new url(pictureurl); bitmap bm = bitmapfactory.decodestream(newurl.openconnection().getinputstream()); // openfileoutput() method creates file on phone/internal storage in context of application final fileoutputstream fos = context.openfileoutput(prefix + id +".jpeg", context.mode_private); // use compress method on bitmap object write image outputstream bm.compress(compressformat.jpeg, 100, fos); }
everything looks fine when execute method, in nothing save... when try read file memory method:
private bitmap getstoredbitmapfrommemory(int idavatar) { file cachedir = context.getcachedir(); file f = new file(cachedir, prefix + integer.tostring(idavatar) + ".jpeg"); fileinputstream fis = null; try { fis = new fileinputstream(f); } catch (filenotfoundexception e) { e.printstacktrace(); } return bitmapfactory.decodestream(fis); }
it's throwing exception:
05-02 10:50:22.487: w/system.err(25805): java.io.filenotfoundexception: /data/data/com.example.xxxx/cache/avatar_400021371.jpeg: open failed: enoent (no such file or directory) 05-02 10:50:22.497: w/system.err(25805): @ libcore.io.iobridge.open(iobridge.java:416) 05-02 10:50:22.497: w/system.err(25805): @ java.io.fileinputstream.<init>(fileinputstream.java:78) 05-02 10:50:22.497: w/system.err(25805): @ com.example.xxxx.performer.getstoredbitmapfrommemory(performer.java:140)
what's wrong storebitmapinmemory??
you have use openfileinput
read file stored openfileoutput
.
here doc openfileinput
Comments
Post a Comment