当前位置:网站首页>递归遍历目录结构和树状展现
递归遍历目录结构和树状展现
2022-06-26 05:05:00 【浅墨cgz】
代码片段,注意代码示例地址。是自定义的。
import java.io.File;
public class TestFile6 {
public static void main(String[] args) {
File f = new File("d:/电影");
printFile(f, 0);
}
/** * 打印文件信息 * @param file 文件名称 * @param level 层次数(实际就是:第几次递归调用) */
static void printFile(File file, int level) {
//输出层次数
for (int i = 0; i < level; i++) {
System.out.print("-");
}
//输出文件名
System.out.println(file.getName());
//如果file是目录,则获取子文件列表,并对每个子文件进行相同的操作
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File temp : files) {
//递归调用该方法:注意等+1
printFile(temp, level + 1);
}
}
}
}


边栏推荐
- 6.1 - 6.2 公钥密码学简介
- Multipass Chinese document - remove instance
- Use fill and fill in Matplotlib_ Between fill the blank area between functions
- Yolov5 super parameter setting and data enhancement analysis
- ThreadPoolExecutor实现文件上传批量插入数据
- Zhongshanshan: engineers after being blasted will take off | ONEFLOW u
- 超高精度定位系统中的UWB是什么
- Multipass Chinese document - use instance command alias
- 【Latex】错误类型总结(持更)
- 0622 horse palm fell 9%
猜你喜欢
![[unity3d] collider assembly](/img/de/29ecf4612c540e2df715f56c31cf1a.png)
[unity3d] collider assembly

Second day of deep learning and tensorfow

Multipass Chinese document - setup driver

【Unity3D】刚体组件Rigidbody

Codeforces Round #802 (Div. 2)(A-D)

Rsync common error messages (common errors on the window)
Technical past: tcp/ip protocol that has changed the world (precious pictures, caution for mobile phones)

torchvision_transform(图像增强)

AD教程系列 | 4 - 创建集成库文件

How MySQL deletes all redundant duplicate data
随机推荐
Sentimentin tensorflow_ analysis_ layer
Using Matplotlib to add an external image at the canvas level
torchvision_transform(图像增强)
Datetime data type ---now() gets the current time, datetime() creation date, performs mathematical operations, and to_ Datetime() converts to date type and extracts various parts of date
Using requests library and re library to crawl web pages
localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。
Status of processes and communication between processes
ThreadPoolExecutor implements file uploading and batch inserting data
2022.2.17
2.< tag-动态规划和常规问题>lt.343. 整数拆分
86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
2022.1.24
Difference between return and yield
ThreadPoolExecutor实现文件上传批量插入数据
Multipass Chinese documents - improve mount performance
Floyd
Hash problem
UWB超高精度定位系统架构图
[unity3d] collider assembly