#1
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);
}
}
#2(根)
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();
}