forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.java
More file actions
38 lines (32 loc) · 1.01 KB
/
MainFile.java
File metadata and controls
38 lines (32 loc) · 1.01 KB
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
36
37
38
package com.urise.webapp;
import java.io.File;
import java.io.IOException;
public class MainFile {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
/*текущий каталог*/
File dir = new File(".\\.");
try {
findFiles(dir);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void findFiles(File file) throws IOException {
if (file.isDirectory()) {
System.out.println(sb.toString() + "Directory: " + file.getName());
File[] list = file.listFiles();
if (list == null) {
System.out.println("Directory is empty!");
return;
}
sb.append(" ");
for (int i = list.length; --i >= 0; ) {
findFiles(list[i]);
}
sb.delete(sb.length() - 1, sb.length());
} else {
System.out.println(sb.toString() + file.getName());
}
}
}