java - Save image Uri as an image -


so doing receiving data intent app. getting image attempting save it

  void savefile(uri sourceuri) {     string sourcefilename= sourceuri.getpath();     file mediastoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "photosaver");       bufferedinputstream bis = null;     bufferedoutputstream bos = null;      try {         bis = new bufferedinputstream(new fileinputstream(sourcefilename));         bos = new bufferedoutputstream(new fileoutputstream(mediastoragedir, false));         byte[] buf = new byte[1024];         bis.read(buf);         {             bos.write(buf);         } while(bis.read(buf) != -1);     } catch (ioexception e) {      } {         try {             if (bis != null) bis.close();             if (bos != null) bos.close();         } catch (ioexception e) {          }     }      sendbroadcast(new intent(intent.action_media_mounted, uri.parse("file://" + new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "photosaver"))));  } 

you should reading till reach end of input stream , flush output stream. this:

     // file read end      while ((value = bis.read()) != -1) {         bos.write(value);      }       // invokes flush force bytes written out baos      bos.flush(); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -