I want to choose image from sdcard and encrypt them. i have some problem with java io exception - permission denied. i declared use permission in android manifest READ and WRITE EXTERNAL STORAGE but it doesn't work
then I open Device File Explorer and check permission, all of them don't have permission write
my code:
File file = new File(uri_result);//create path from uri
final String[] split = file.getPath().split(":");//split the path.
String filePath = split[2];
try {
FileInputStream fis = new FileInputStream(filePath);
File fos_enc = new File( Environment.getExternalStorageDirectory().getAbsolutePath()+"/abcd.jpg");
fos_enc.createNewFile();
FileOutputStream fos = new FileOutputStream(fos_enc);
byte[] k = "123456".getBytes();
SecretKeySpec key = new SecretKeySpec(k,"DES");
Cipher enc = Cipher.getInstance("DES");
enc.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(fos, enc);
byte[] buf = new byte[1024];
int read;
while ((read = fis.read(buf)) != -1) {
cos.write(buf,0,read);
}
fis.close();
fos.flush();
cos.close();
showAlertDialog("Encrypt Successfully");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
permission denied because the sdcard don't access write the file and i have no idea to resolve this. Hepl me please :)
fos_enc=newFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/abcd.jpg");
runtime
as well. – Yupi