tags:

views:

233

answers:

2

Hi,

I downloaded a jpg from the net, I'd like to save it to disk then load it again. I'm trying something like this:

Bitmap bmp = ...; // loaded from net.
File file = new File(Environment.getExternalStorageDirectory(), "tmp.jpg");
OutputStream out = getContentResolver().openOutputStream(Uri.parse(file.getAbsolutePath())); 
bmp.compress(Bitmap.CompressFormat.JPEG, 70, out); 
out.flush();
out.close();

...

File f2 = new File(Environment.getExternalStorageDirectory(), "tmp.jpg");
Uri uri = Uri.fromFile(f2);

but I keep getting an error on the second line when trying to create the new File() instance:

java.io.FileNotFoundException: No content provider: /sdcard/tmp.jpg

I'm using a 2.0 emulator and it has an sdcard. What am I doing wrong?

Thanks

+1  A: 

I have a test app with an SD card, so I added your second line to it and it ran fine:

File file = new File(Environment.getExternalStorageDirectory(), "tmp.jpg");

Are you sure you created the card correctly, and assuming you're using Eclipse, did you tell Eclipse about the card (-sdcard \sdcard.iso)? See:

http://www.androidref.com/#SDCard

Jay

AndroidRef.com
A: 

It's because you are using getContentResolver().openOutputStream(). You should just create a FileOutputStream instead. And you don't need to use Uris.

Romain Guy