我想让应用程序创建一个新目录来将下载的图像存储在 sdcard 中。我尝试了一些方法,但似乎仍然无法正常工作。我也在 android manifest 中包含了外部存储的权限。任何意见将不胜感激。
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);
以下是我从运行中得到的。
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
编辑 下面是我如何处理位图。
bm.compress(Bitmap.CompressFormat.JPEG, 85, fos);