我使用下面的代碼保存圖片到SD卡,但我不能這樣做,無法在SD卡的Android保存圖像
這裏是我的代碼
try {
root.mkdirs();
File sdImageMainDirectory = new File(root, myid + "__" + fileName);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
fOut = new FileOutputStream(sdImageMainDirectory);
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
Toast.makeText(this, "Image Saved",Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
這是錯誤
04-14 13:34:07.723: W/System.err(23073): java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.goldenedge.poetry/Urdu/Festive Poetry/4__311159_248676158509124_848180994_n.jpg
04-14 13:34:07.724: W/System.err(23073): : open failed: EINVAL (Invalid argument)
04-14 13:34:07.725: W/System.err(23073): at libcore.io.IoBridge.open(IoBridge.java:448)
04-14 13:34:07.726: W/System.err(23073): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
04-14 13:34:07.726: W/System.err(23073): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
04-14 13:34:07.726: W/System.err(23073): at com.golden.ViewImage.onOptionsItemSelected(ViewImage.java:106)
04-14 13:34:07.727: W/System.err(23073): at android.app.Activity.onMenuItemSelected(Activity.java:2526)
04-14 13:34:07.727: W/System.err(23073): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:966)
04-14 13:34:07.727: W/System.err(23073): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
04-14 13:34:07.727: W/System.err(23073): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
04-14 13:34:07.728: W/System.err(23073): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
04-14 13:34:07.728: W/System.err(23073): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:468)
04-14 13:34:07.728: W/System.err(23073): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:126)
04-14 13:34:07.728: W/System.err(23073): at android.view.View$PerformClick.run(View.java:14155)
04-14 13:34:07.729: W/System.err(23073): at android.os.Handler.handleCallback(Handler.java:605)
04-14 13:34:07.729: W/System.err(23073): at android.os.Handler.dispatchMessage(Handler.java:92)
04-14 13:34:07.729: W/System.err(23073): at android.os.Looper.loop(Looper.java:137)
04-14 13:34:07.730: W/System.err(23073): at android.app.ActivityThread.main(ActivityThread.java:4666)
04-14 13:34:07.730: W/System.err(23073): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 13:34:07.730: W/System.err(23073): at java.lang.reflect.Method.invoke(Method.java:511)
04-14 13:34:07.731: W/System.err(23073): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
04-14 13:34:07.731: W/System.err(23073): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
04-14 13:34:07.731: W/System.err(23073): at dalvik.system.NativeStart.main(Native Method)
04-14 13:34:07.732: W/System.err(23073): Caused by: libcore.io.ErrnoException: open failed: EINVAL (Invalid argument)
04-14 13:34:07.733: W/System.err(23073): at libcore.io.Posix.open(Native Method)
04-14 13:34:07.733: W/System.err(23073): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
04-14 13:34:07.733: W/System.err(23073): at libcore.io.IoBridge.open(IoBridge.java:432)
04-14 13:34:07.734: W/System.err(23073): ... 20 more
什麼是你的根路徑。 –
root = new File(Environment.getExternalStorageDirectory() \t \t \t \t + File.separator +「Android/data/com.golustedge.poetry」+ filecatpath); 它正確地在根路徑創建文件夾(root.mkdirs();)。 – user934820
和你的filecatpath是什麼。 –