当前位置:网站首页>递归遍历目录结构和树状展现
递归遍历目录结构和树状展现
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);
}
}
}
}


边栏推荐
- Transport layer TCP protocol and UDP protocol
- Computer Vision Tools Chain
- ECCV 2020 double champion team, take you to conquer target detection on the 7th
- Solution to back-off restarting failed container
- Using Matplotlib to add an external image at the canvas level
- ssh连win10报错:Permission denied (publickey,keyboard-interactive).
- ModuleNotFoundError: No module named ‘numpy‘
- 天才制造者:独行侠、科技巨头和AI|深度学习崛起十年
- Introduction to classification data cotegory and properties and methods of common APIs
- date_ Range creation date range freq parameter value table and creation example
猜你喜欢

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)

5. < tag stack and general problems > supplement: lt.946 Verify the stack sequence (the same as the push in and pop-up sequence of offer 31. stack)

Second day of deep learning and tensorfow

localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。

-Discrete Mathematics - Analysis of final exercises
![[unity3d] human computer interaction input](/img/4d/47f6d40bb82400fe9c6d624c8892f7.png)
[unity3d] human computer interaction input

一个从坟墓里爬出的公司

LeetCode 19. Delete the penultimate node of the linked list

ModuleNotFoundError: No module named ‘numpy‘

What is UWB in ultra-high precision positioning system
随机推荐
Method of saving pictures in wechat applet
【Unity3D】人机交互Input
Introduction to classification data cotegory and properties and methods of common APIs
A ZABBIX self discovery script (shell Basics)
Generalized linear model (logistic regression, Poisson regression)
ModuleNotFoundError: No module named ‘numpy‘
Ai+ remote sensing: releasing the value of each pixel
Illustration of ONEFLOW's learning rate adjustment strategy
Zuul implements dynamic routing
0622 horse palm fell 9%
Modify the case of the string title(), upper(), lower()
Multipass Chinese document - use multipass service to authorize the client
FastAdmin Apache下设置伪静态
Use to_ Numeric to numeric type
Datetime data type - min() get the earliest date and date_ Range() creates a date range, timestamp() creates a timestamp, and tz() changes the time zone
YOLOv5-6.0的一些参数设置和特征图可视化
[greedy college] Figure neural network advanced training camp
PSIM software learning ---08 call of C program block
[unity3d] human computer interaction input
PHP one sentence Trojan horse