I can't seem to write to the cache directory. My relevant code is:

Method (String url) {
File cacheFile = new File(mCtx.getCacheDir(), url.replace('/', 's'));
cacheFile.createNewFile();
FileOutputStream fos = new FileOutputStream(cacheFile);
// or FileOutputStream fos = mCtx.openFileOutput(cacheFile.getPath(),
mCtx.MODE_PRIVATE);
URL url2 = new URL(url)
InputStream is = (InputStream)url2.getContent(url);
Bitmap mBitmap = BitmapFactory.decodeStream(is);
mBitmap.compress(CompressFormat.JPEG, 75, fos);
// or byte[] b = new byte[is.available()];
//      is.read(b);
//      fos.write(b);
//      fos.flush();
//      fos.close();
}

I know openFileOutput doesn't accept path delimiters, just filenames,
but it seems to be the preferred method of writing to files.
Additionally converting from an inputstream (which reads a jpg at a
url) to a drawable to a bitmap back to a jpeg seems strange but
neither it nor the reading from and writing to a byte array seem to
work. Is there anything wrong with the code above or does anyone know
of another way to cache images without using webview?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to