**Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)** at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.snatik.storage.Storage.copy(Storage.java:278) at com.snatik.storage.Storage.move(Storage.java:293) at com.snatik.storage.app.MainActivity$1.onClick(MainActivity.java:90) at android.view.View.performClick(View.java:5233) at android.view.View$PerformClick.run(View.java:21211) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5539) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:0)
这个问题是因为您没有权限在SD卡上执行此操作,在5.0版之后的Android设备上,您必须在运行时获得权限,而不仅仅是在AndroidManifest.xml中询问它们 为了在运行时获得Android权限,我建议你使用EasyPermissions库https://github.com/googlesamples/easypermissions 那么你可以处理如下所示的permissionGranted或permissionDenied之类的情况:
String[] perms = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION};
EasyPermissions.requestPermissions(this, getString(R.string.camera_and_location_rationale),
RC_CAMERA_AND_LOCATION, perms);
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
// Some permissions have been granted
// ...
}
@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
// Some permissions have been denied
// ...
}