0

I am new to android so please excuse me for this noob question.

i wanted to save bmp in my external storage after some research i found out that i need to compress the bmp and then use the flush method of FileOutputStream which will save the bmp in my desired location but how does this work and is there any way to use write function by converting the image to raw bytes of data.

File file = new File(folder,s);
FileOutputStream fos = null;
try {
     fos = new FileOutputStream(file);
     b.compress(Bitmap.CompressFormat.PNG, 100, fos);
     try {
           fos.flush();
         } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
Nikhil Soni
  • 119
  • 9
  • 2
    Flushing simply asks a stream to "write" whatever content has been "cached" so far. You see, most streams do not "write" immediately when you push data into them; they wait until a reasonable amount of data has been sent to the stream. But for FileOutputStreams ... flushing is a **no op** anyway. See: http://stackoverflow.com/questions/31456660/fileoutputstream-does-the-close-method-calls-also-flush ... and hint for the future: you do not need other people to figure such things. You are expected to do some prior research; like using a search engine to lookup some keywords! – GhostCat Aug 11 '16 at 09:35
  • sorry i will research the topics more to avoid this kind of noob questions and thanks – Nikhil Soni Aug 11 '16 at 10:23

0 Answers0