Save .gif to sd card
<p>I am still new in Android programming,
and I wanna do something, </p>

<ol>
<li>download <code>.gif</code> from url</li>
<li>save that downloaded <code>.gif</code> to my sd card</li>
<li>call it using glide</li>
</ol>

<p>When I download <code>.gif</code>, and write it to sdcard, it is not readable.
and the size bigger than original file.</p>

<p>here is the code I use :</p>

<pre><code>URL url = new URL(imgUrl + params[0]);

File file = new File(path + params[0]);

long startTime = System.currentTimeMillis();

URLConnection ucon = url.openConnection();
Log.d(TAG, "on do in background, url open connection");

InputStream is = ucon.getInputStream();
Log.d(TAG, "on do in background, url get input stream");
BufferedInputStream bis = new BufferedInputStream(is);
Log.d(TAG, "on do in background, create buffered input stream");

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Log.d(TAG, "on do in background, create buffered array output stream");

byte[] img = new byte[1024];

int current = 0;

Log.d(TAG, "on do in background, write byte to baos");
while ((current = bis.read()) != -1) {
    baos.write(img, 0, current);
}


Log.d(TAG, "on do in background, done write");

Log.d(TAG, "on do in background, create fos");
FileOutputStream fos = new FileOutputStream(file);
fos.write(baos.toByteArray());

Log.d(TAG, "on do in background, write to fos");
fos.flush();

fos.close();
is.close();
Log.d(TAG, "on do in background, done write to fos");
</code></pre>

<p>thx before.</p>