title: Android: How to execute shell command 'rm' in app
body: <p>I can easily use 'rm /data/system/[file]' from adb shell but from app this is not working. </p>
  
  <p>Commands 'du', 'ls', 'echo' works fine from code but command 'rm' is not working. It is not even working on sdcard. </p>
  
  <p>Code I have tried:</p>
  
  <p>1)</p>
  
  <pre><code>String[] cmd = { "/system/bin/sh", "-c", "rm -r /sdcard/1" }; 
      try {
  
          Process process = Runtime.getRuntime().exec(cmd);//execute command
  
          //read the output of command
          InputStreamReader reader = new InputStreamReader(process.getInputStream()); 
  .....
  </code></pre>
  
  <p>2) Same code as (1), with "su" instead of "/system/bin/sh"</p>
  
  <p>3)</p>
  
  <pre><code>process=Runtime.getRuntime().exec("/system/bin/sh");
  DataOutputStream os = new DataOutputStream(process.getOutputStream());
  os.writeBytes("rm -r /sdcard/1\n");
  os.flush();
  os.writeBytes("exit\n");
  os.flush();
  process.waitFor();
  </code></pre>
  
  <p>4) Same code as (3), with 'su' instead of '/system/bin/sh'</p>