I am trying to write on the pdf file after creating it through intent but I am getting a permission denied error.
open failed: EACCES (Permission denied)
the intent i am using to create the file
  Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("application/pdf");
        intent.putExtra(Intent.EXTRA_TITLE,userInputFileName);
        ActivityForresults.launch(intent);
the code inside the ActivityForresults
   Intent data = result.getData();
                        String path = data.getData().getPath();
                        File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
                        File file = new File(root, userInputFileName);
                        try {
                            FileOutputStream fileOutputStream = new FileOutputStream(file); 
                            pdfDocument.writeTo(fileOutputStream);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
I have added install time permission
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I have also added run time permission
  String[] galleryPermissions = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.MANAGE_DOCUMENTS};
        if (EasyPermissions.hasPermissions(getActivity(), galleryPermissions)) {
            Log.i("local-dev", "permissions are granted");
        } else {
            EasyPermissions.requestPermissions(this, "Access for storage",
                    101, galleryPermissions);
        }