从storage0删除文件夹 - android

时间:2016-04-28 13:24:08

标签: android eclipse android-studio

我无法删除存储空间中的文件夹。这是我的代码

  File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/sdcard/folder" );
                if (dir.isDirectory())
                {
                    String[] children = dir.list();
                    for (int i = 0; i < children.length; i++)
                    {
                        new File(dir, children[i]).delete();
                    }
                }

1 个答案:

答案 0 :(得分:0)

这就是你如何做到的

但首先你需要在清单中拥有此权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

然后

File dir = new File(Environment.getExternalStorageDirectory()+"/sdcard/folder"); 
if (dir.isDirectory()) 
{
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
{
   new File(dir, children[i]).delete();
}
}