更新时间:2022-10-20 20:01:28
公共静态布尔deleteDirectory(文件路径){
// TODO自动生成方法存根
如果(path.exists()){
文件[]文件= path.listFiles();
的for(int i = 0; I< files.length;我++){
如果(文件[I] .isDirectory()){
deleteDirectory(文件[I]);
}
其他 {
文件[I] .delete();
}
}
}
返程(path.delete());
}
添加code就叫它曾经当需要使用目录的路径删除或要删除的文件
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.
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