I use this code to delete all files:
File root = new File(\"root path\");
File[] Files = root.listFiles();
if(Files != null) {
int j;
for(j = 0; j < F
File mFile = new File(Environment.getExternalStorageDirectory() + "/folder");
try {
deleteFolder(mFile);
} catch (IOException e) {
Toast.makeText(getContext(), "Unable to delete folder", Toast.LENGTH_SHORT).show();
}
public void deleteFolder(File folder) throws IOException {
if (folder.isDirectory()) {
for (File ct : folder.listFiles()){
deleteFolder(ct);
}
}
if (!folder.delete()) {
throw new FileNotFoundException("Unable to delete: " + folder);
}
}
try {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(p.getOutputStream());
outputStream.writeBytes("rm -Rf /system/file.txt\n");
outputStream.flush();
p.waitFor();
} catch (IOException | InterruptedException e) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}