java newfile 失败_java.io.FileNotFoundException:/ storage / emulated / 0 / New file.txt:打开失败:EACCES(权限...

我一直在尝试加密文件,并将这些文件写回到同一位置。但是我收到错误消息说"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 {

// 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();

}

}

我在按钮内使用了这种方法

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);

}

}

});

仍然我无法配置此错误。请有人帮忙!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值