java.io.FileNotFoundException: / storage / emulated / 0 / Nouveau fichier.txt: ouverture échouée: EACCES (autorisation refusée)

J'ai essayé de chiffrer des fichiers et écrire les fichiers sur le même endroit. Mais j'ai eu le message d'erreur disant "java.io.FileNotFoundException: /storage/emulated/0/Nouvelle file.txt: open failed: EACCES (Permission denied)".

Mon fichier Manifeste est ce

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tdk.mytestapplication2">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


<application
    android:allowBackup="true"

Je pense que j'ai fourni de l'autorisation adéquate. Et le code de messagerie unifiée à l'aide de crypter des fichiers, c'est ça.

public static void encrypt(SecretKey secretKey, String filePath){
    try {
        //Here you read the cleartext.
        FileInputStream fis = new FileInputStream(filePath);
        //This stream write the encrypted text. This stream will be wrapped by another stream.
        FileOutputStream fos = new FileOutputStream(filePath);

        //Create cipher
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        //Wrap the output stream
        CipherOutputStream cos = new CipherOutputStream(fos, cipher);

        //Write bytes
        int b;
        byte[] d = new byte[8];
        while ((b = fis.read(d)) != -1) {
            cos.write(d, 0, b);
        }

        //Flush and close streams.
        cos.flush();
        cos.close();
        fis.close();

    }catch(IOException e){
        e.printStackTrace();
    }catch (NoSuchAlgorithmException e){
        e.printStackTrace();
    }catch(NoSuchPaddingException e){
        e.printStackTrace();
    }catch(InvalidKeyException e){
        e.printStackTrace();
    }
}

Et j'ai utilisé cette méthode à l'intérieur d'un bouton

Button btnEncrypt = (Button) findViewById(R.id.btnEnc);
    btnEncrypt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            aesKey = EncAndDec.generateKey();
            String filePath = editText.getText().toString();
            //Generating the file hash
            String md5Hash = MD5Hash.getMD5(filePath);

            System.out.println(aesKey.toString());
            System.out.println(filePath);
            System.out.println(md5Hash);

            //Encrypting the file
            for(int i=1; i<100; i++) {
                EncAndDec.encrypt(aesKey, filePath);
            }
        }
    });

Encore je n'arrivais pas à configurer cette erreur. Merci de l'aide de quelqu'un!

source d'informationauteur Tharindu