当前位置:网站首页>8. Recursively traverse and delete cases
8. Recursively traverse and delete cases
2022-08-09 09:33:00 【come here my bear】
Recursively traverse and delete folders case
package com.io.file;import java.io.File;/*** recursively traverse and delete*/public class Demo3 {public static void main(String[] args) {listDir(new File("E:\\Desktop\\aa"));deleteDir(new File("E:\\Desktop\\aa"));}// recursively traverse the folderpublic static void listDir(File dir){File[] files = dir.listFiles();System.out.println(dir.getAbsolutePath());if (files!=null&&files.length>0){for (File file : files) {if (file.isDirectory()){listDir(file); // recurse}else {System.out.println(file.getAbsolutePath());}}}}// recursively delete folderspublic static void deleteDir(File dir){File[] files = dir.listFiles();if (files!=null && files.length>0){for (File file : files) {if (file.isDirectory()){deleteDir(file); // recursive}else {// delete inner fileSystem.out.println(file.getAbsolutePath() + "delete" + file.delete());}}}// delete the outermost folder dirSystem.out.println(dir.getAbsolutePath() + "delete" + dir.delete());}}
边栏推荐
猜你喜欢
随机推荐
What does the test plan include?What is the purpose and meaning?
try catch 对性能影响
软件测试流程包括哪些内容?测试方法有哪些?
unittest测试框架原理及测试流程解析,看完绝对有提升
你一定要看的安装及卸载测试用例的步骤及方法总结
div模拟textarea文本框,输入文字高度自适应,且实现字数统计和限制
测试计划包括哪些内容?目的和意义是什么?
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
Rights management model, ACL, RBAC and ABAC (steps)
搭建Tigase进行二次开发
软件测试外包公司怎么样?有什么好处和坏处?为什么没人去?
Understanding of PID control motor output as motor PWM duty cycle input
通用的测试用例编写大全(登录测试/web测试等)
[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)
黑盒测试常见错误类型说明及解决方法有哪些?
STM32F103实现IAP在线升级应用程序
Domestic with Google earth software, see the download 19th level high-resolution satellite images so easy!
【分布式事务】
4.泛型和工具类
4. Character stream