我一直在尝试加密文件并将这些文件重新写回到同一个地方.但是我收到了错误消息"java.io.FileNotFoundException: /storage/emulated/0/New file.txt: open failed: EACCES (Permission denied)".
我的Manifest档案是这个
<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"
Run Code Online (Sandbox Code Playgroud)
我想我已在那里提供了正确的许可.我用来加密文件的代码就是这个.
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 = …Run Code Online (Sandbox Code Playgroud)