java.io.FileNotFoundException: (Permission denied) when writing an object using ObjectOutputStream

后端 未结 3 1733
予麋鹿
予麋鹿 2021-01-20 02:42

I have been trying to work around this for several hours and I am extremely frustrated so I am coming to you guys for some guidance.

I am trying to save and retriev

相关标签:
3条回答
  • 2021-01-20 03:07

    This java.io.FileNotFoundException: /storage/emulated/0myFile.ser looks like you are missing a '/' in the path.

    Use

    String path = Environment.getExternalStorageDirectory().getAbsolutePath() + '/';
    
    0 讨论(0)
  • 2021-01-20 03:10

    Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running

    Everything you need to know is in :

    https://developer.android.com/training/permissions/requesting.html

    The other error has nothing to do with it

    0 讨论(0)
  • 2021-01-20 03:18

    You've added the permission in manifest, So I'm sure you are not asking runtime permissions. If you are using SDK 23 or higher, Ask runtime permission. For reference I'm adding some snippet here:

    if(Build.VERSION.SDK_INT>22){
         requestPermissions(new String[] {YOUR_PERMISSIONS AS STRING}, 1);
    }
    

    and to check whether permission is granted or not, you need to use onRequestPermissionResults() method.

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case 1: {
                if (!(grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
                    Toast.makeText(addAlarm.this, "Permission denied to access your location.", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题