删除文件夹及下面所有文件
public static void deleteDirectory(String path)
{
if (null == path)
{
path = "/sdcard/aico/res";
index = 1;
}
File folder = new File(path);
if (!folder.exists())
{
return;
}
if (folder.isFile())
{
folder.delete();
return;
}
String[] tempList = folder.list();
File temp = null;
for (int i = 0; i < tempList.length; i++)
{
if (path.endsWith(File.separator))
{
temp = new File(path + tempList[i]);
}
else
{
temp = new File(path + File.separator + tempList[i]);
}
// 如果是文件,直接删除
if (temp.isFile())
{
temp.delete();
}
// 如果是文件夹
if (temp.isDirectory())
{
deleteDirectory(temp.getPath());
}
temp.delete();
}
folder.delete();
}