Java 删除android中的zip文件夹
在文件中使用delete()方法后。 filePath是包含zip文件路径的字符串Java 删除android中的zip文件夹,java,android,delete-file,Java,Android,Delete File,在文件中使用delete()方法后。 filePath是包含zip文件路径的字符串 Perform above code for delete zip folder but its not working Please help me if anyone have solution Thanks in advance.. //必须检查“已删除”是否为真。如果文件已成功删除,则为true File file = new File(filePath); 使用下面的方法 /** *清除/删除文
Perform above code for delete zip folder but its not working
Please help me if anyone have solution
Thanks in advance..
//必须检查“已删除”是否为真。如果文件已成功删除,则为true
File file = new File(filePath);
使用下面的方法
/**
*清除/删除文件/目录中的所有内容
*
*@param文件/文件夹
*@成功删除所有内容时返回true
*确保该文件不为空
*/
公共布尔clearDirectory(@NonNull文件){
布尔成功=假;
if(file.isDirectory())
对于(文件子项:File.listFiles())
clearDirectory(子目录);
success=file.delete();
回归成功;
}
试试看
Use below method
/**
* Clear/Delete all the contents in file/Directory
*
* @param file file/folder
* @return true on successfull deletion of all content
* <b>Make sure file it is not null</b>
*/
public boolean clearDirectory(@NonNull File file) {
boolean success = false;
if (file.isDirectory())
for (File child : file.listFiles())
clearDirectory(child);
success = file.delete();
return success;
}
文件文件=新文件(删除文件路径);
boolean deleted==file.deleted()
deleteFilePath是包含zip文件路径的字符串
Perform above code for delete zip folder but its not working
Please help me if anyone have solution
Thanks in advance..
如果deleted为true。如果文件被成功删除,则是正确的。可能重复@RanjanDas我尝试您的代码,但它只删除zip文件的内容,而不删除zip文件。请给出zip文件的路径,而不是它的内容。zip文件夹路径::/storage/emulated/0/PhotoResizer/PhotoResizer\u 153370732194.zip我使用上述路径删除zip文件夹,但只删除zip文件夹的内容,而不删除zip文件;在我的情况下,当重新创建zipfile时。它解决了我的问题。谢谢
Use below method
/**
* Clear/Delete all the contents in file/Directory
*
* @param file file/folder
* @return true on successfull deletion of all content
* <b>Make sure file it is not null</b>
*/
public boolean clearDirectory(@NonNull File file) {
boolean success = false;
if (file.isDirectory())
for (File child : file.listFiles())
clearDirectory(child);
success = file.delete();
return success;
}
public static final String ZIP_FILES_DIR = "Download/FolderNAME";
File directoryPath = new File(Environment.getExternalStorageDirectory()+ File.separator + ZIP_FILES_DIR);
if (directoryPath.delete()) {
//do whatever you want
}