I wanted to the application to create a new directory to store downloaded image inside sdcard. I tried a few methods but still I can't seems to get it work. I included permission for External Storage in android manifest as well. Any comments will be appreciated.
Bitmap bm = null;
InputStream in;
in = new java.net.URL("http://blogs.computerworld.com/sites/computerworld.com/files/u177/google-nexus-4.jpg").openStream();
bm = BitmapFactory.decodeStream(new PatchInputStream(in));
File file = new File(Environment.getExternalStorageDirectory() + "/map");
file.mkdirs();
File outputFile = new File(file, "Image"+NumIncrease);
FileOutputStream fos = new FileOutputStream(outputFile);
Below is what I get from running this.
12-05 15:55:25.566: D/skia(4244): ---- read threw an exception
12-05 15:55:25.585: D/skia(4244): ---- read threw an exception
12-05 15:55:25.585: W/System.err(4244): java.io.IOException: Is a directory
12-05 15:55:25.585: W/System.err(4244): at org.apache.harmony.luni.platform.OSFileSystem.read(Native Method)
12-05 15:55:25.585: W/System.err(4244): at dalvik.system.BlockGuard$WrappedFileSystem.read(BlockGuard.java:165)
12-05 15:55:25.585: W/System.err(4244): at java.io.FileInputStream.read(FileInputStream.java:290)
12-05 15:55:25.585: W/System.err(4244): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:166)
12-05 15:55:25.863: E/MediaStore(4244): Failed to create thumbnail, removing original
EDIT Below is how I handle the bitmap.
bm.compress(Bitmap.CompressFormat.JPEG, 85, fos);