我对 Java 很陌生,我想知道是否有任何方法可以删除可能包含某些文件的文件夹,就像命令行中的“rm -rf directory/”一样。
这就是我正在做的事情。
public static boolean checkUnzippedExistence(String deleteKeyword) {
List<String> foldersList = new ArrayList<String>();
String absPath = Environment.getExternalStorageDirectory().getPath();
File[] files = new File(absPath).listFiles();
boolean existence = false;
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory() && files[i].getName().contains(deleteKeyword)) {
//some method/function to delete
}
}
existence = true;
}
return existence;
}
提前致谢。
最佳答案
您可以使用Apache Commons FileUtils 。它包含可用于文件操作的出色实用方法:
Apache Commons 的 Gradle 依赖项:
compile group: 'commons-io', name: 'commons-io', version: '2.4'
关于java - Android Java中递归文件夹删除(API17),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45558917/