How to delete all the files from sd card in android? [duplicate]

眉间皱痕 提交于 2019-12-06 16:51:04

问题


Possible Duplicate:
How to delete entire contents of sdcard programmatically in Android 2.2

I want to clear all the files from android device programmatically.

Can anyone suggest me the way or code, Hence I can perform this operation please...

Thanks in advance.


回答1:


public static boolean deleteDirectory(File path) {
        // TODO Auto-generated method stub
        if( path.exists() ) {
            File[] files = path.listFiles();
            for(int i=0; i<files.length; i++) {
                if(files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                }
                else {
                    files[i].delete();
                }
            }
        }
        return(path.delete());
    }

add the code just call it when ever you require using the path of the directory to delete or the file to delete



来源:https://stackoverflow.com/questions/10361145/how-to-delete-all-the-files-from-sd-card-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!