-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.java
More file actions
35 lines (29 loc) · 990 Bytes
/
MainFile.java
File metadata and controls
35 lines (29 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ru.javaops.webapp;
import java.io.File;
public class MainFile {
public static void main(String[] args) {
printAllFileNames("./src/ru/javaops/webapp");
}
public static void printAllFileNames(String directoryPath) {
printFormattedPath(directoryPath, 0);
}
private static void printFormattedPath(String directoryPath, int offset) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < offset; i++) {
sb.append(" ");
}
File file = new File(directoryPath);
System.out.println(sb + ".." + file.getName());
File[] files = file.listFiles();
if (files != null) {
for (File fl : files) {
if (fl.isFile()) {
System.out.println(sb + " " + fl.getName());
}
if (fl.isDirectory()) {
printFormattedPath(fl.getPath(), offset + 2);
}
}
}
}
}