我想让应用程序创建一个新目录,将下载的图像存储在sdcard中。我尝试了一些方法,但我似乎无法让它工作。我也在android清单中包含了外部存储的权限。任何意见将不胜感激。
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);
答案 0 :(得分:0)
以下几点可以帮到你
进一步阅读