I save the files in the application directory, but for some reason after updating the application, they are deleted. Tell me how can I fix it?

try { final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(4096, new SecureRandom()); final KeyPair key = keyGen.generateKeyPair(); File privateKeyFile = new File(this.getFilesDir().toString() + "/" + md5(nickname.getText().toString() + password.getText().toString()) + "_private_key"); File publicKeyFile = new File(this.getFilesDir().toString() + "/" + md5(nickname.getText().toString() + password.getText().toString()) + "_public_key"); if (privateKeyFile.getParentFile() != null) { privateKeyFile.getParentFile().mkdirs(); } privateKeyFile.createNewFile(); if (publicKeyFile.getParentFile() != null) { publicKeyFile.getParentFile().mkdirs(); } publicKeyFile.createNewFile(); BufferedWriter pubOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(publicKeyFile))); pubOut.write(byte2Hex(key.getPublic().getEncoded())); pubOut.flush(); pubOut.close(); BufferedWriter privOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(privateKeyFile))); privOut.write(byte2Hex(key.getPrivate().getEncoded())); privOut.flush(); privOut.close(); open_key_global = key.getPublic().toString(); } catch (Exception e) { e.printStackTrace(); Log.d("TAG123", "Ключи шифрования не были созданы"); } 
  • they should not be removed. Have you tried to look with root? - Vladyslav Matviienko

0