File restrictions in android Nugget : I am getting image from gallery / capture with camera. then i want to resize the image if needed and save it to the same location.
To do so i use the following code:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

    File file = new File(photoLocation);
                file.setWritable(true);
                try {

                    if(ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.WRITE_EXTERNAL_STORAGE)==PackageManager.PERMISSION_GRANTED) {
                        FileOutputStream fileOutputStream = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fileOutputStream);
                        fileOutputStream.flush();
                        fileOutputStream.close();
                    }else{
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
                    }

<!-- end snippet -->

Sadly i get FileNotFound error (permmission denaied), I tried the same code on Android 4 device and it works ok so I assume its because of the file access restrictions in android 7.
How can I write to file now?