java.io.FileNotFoundException: /storage/emulated/0/New file.txt: open failed: EACCES (Permission denied)
java.io.FileNotFoundException: /storage/emulated/0/New file.txt: open failed: EACCES (Permission denied)
我一直在尝试对文件进行加密,并将这些文件写回到相同的位置。但是我收到了一个错误消息,显示"java.io.FileNotFoundException: /storage/emulated/0/New file.txt: open failed: EACCES (Permission denied)"。
我的Manifest文件是这样的:
package="com.example.tdk.mytestapplication2"> android:allowBackup="true" 我认为我已经提供了正确的权限。我用于加密文件的代码如下: public static void encrypt(SecretKey secretKey, String filePath){ try { FileInputStream fis = new FileInputStream(filePath); FileOutputStream fos = new FileOutputStream(filePath); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); CipherOutputStream cos = new CipherOutputStream(fos, cipher); int b; byte[] d = new byte[8]; while ((b = fis.read(d)) != -1) { cos.write(d, 0, b); } 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(); } } 我将此方法用于一个按钮: 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(); String md5Hash = MD5Hash.getMD5(filePath); System.out.println(aesKey.toString()); System.out.println(filePath); System.out.println(md5Hash); for(int i=1; i<100; i++) { EncAndDec.encrypt(aesKey, filePath); } } }); 我仍然无法解决这个错误。请有人帮帮我!