问题
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