1

I'm working on a POC where I need to create and later on delete a file in the /data/data dir of a rooted device. I have tried to create a file in the standard way but it throws an PERMISSION_DENNIED exception as expected. I know this is possible because the Root Explorer app can do it.

How can I programatically create/ delete a file via root?

Thank in advance!

android enthusiast
  • 2,160
  • 2
  • 19
  • 37

1 Answers1

0

Based on @GabeSechan comment I was able to achieve this using this commands.

Create new file:

final String[] sCommand = {"su", "-c", "touch /data/..."};
        try {
            Runtime.getRuntime().exec(sCommand);

        } catch (Exception e) {
            Log.e(TAG, "Issue occurred while creating new file " + e.getMessage());
        }
    }

And delete file:

final String[] sCommand = {"su", "-c", "rm /data/..."};
try {
    Runtime.getRuntime().exec(sCommand);

} catch (Exception e) {
    Log.e(TAG, "Issue occurred while deleting " + e.getMessage());
}
android enthusiast
  • 2,160
  • 2
  • 19
  • 37