/** The file structure is like this:
*
* D:\recurDelete\1
* \2\a.txt
* \3\b.txt
* \4\4-1\c.txt
* \4\4-2\
*
* Here example recursive delete a.txt,b.txt,c.txt
*/
public class Test {
private static File file = new File("D:\\recurDelete");
public static void recurDelete(File file) {
File[] files = file.listFiles();
for (File f : files) {
if (f.isDirectory()) {
recurDelete(f);
} else {
f.delete();
}
continue;
}
}
public static void main(String[] args) {
Test.recurDelete(file);
System.out.println("over");
}
}
递归删除文件
最新推荐文章于 2023-05-27 12:17:36 发布