替代目录中的递归文件删除?

时间:2010-07-06 00:16:39

标签: android

//Check that external storage is mounted and accessable
    String accessable = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(accessable)) {
        buildWarningMessage();
    }

//Set the cache directory
        CACHE_DIRECTORY = externalRoot + "/folder/.cache/";



@Override
    protected void onDestroy() {
        super.onDestroy();
        File cacheFile = new File(CACHE_DIRECTORY);
        if (cacheFile.exists()) {
            deleteDir(cacheFile);
        }

我目前正在使用上面的代码创建一个文件夹,用于临时存储应用程序稍后使用的图像。 deleteDir只是用于清空目录的通用递归文件删除。有没有比删除所有内容更好的方法呢?理想情况下,我只想要一个在应用程序关闭时清空的临时文件夹。

1 个答案:

答案 0 :(得分:1)

嗨丹尼尔,您必须删除所有文件夹文件才能删除您的文件夹,(递归文件删除)是唯一的方法。