如何删除java android app目录中的所有文件?当前代码正在删除该文件夹

Nis*_*ara 0 java android android-studio

这是我的代码

private final static String Dir = "/data/data/org.xbmc.kodi/cache/";
private void deleteDir(){
    try{
        /*File dir = Utils.getCacheDir(null, this, false, true);
        File path = new File(dir.getParentFile(), Dir);
        delete(path);*/
        String command = "rm -r "+Dir;
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes(command + "\n");
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();
    }catch(Exception e){}
}
Run Code Online (Sandbox Code Playgroud)

问题是当我运行它时它会删除该文件夹。但我不想删除该文件夹。我想删除里面的所有文件。

Soh*_*hid 6

File dir = new File(Environment.getExternalStorageDirectory()+"Dir_name_here"); 
if (dir.isDirectory()) 
{
    String[] children = dir.list();
    for (int i = 0; i < children.length; i++)
    {
       new File(dir, children[i]).delete();
    }
}
Run Code Online (Sandbox Code Playgroud)

源线程。