import java io import java util public class Main static class Leveled

 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
39
import java.io.*;
import java.util.*;
public class Main {
static class LeveledFile {
public LeveledFile(File file, int level) {
this.file = file;
this.level = level;
}
public int getLevel() {
return level;
}
public File getFile() {
return file;
}
private File file;
private int level;
}
public static void main(String[] args) {
int maxLevel = 3;
LinkedList<LeveledFile> stack = new LinkedList<LeveledFile>();
stack.addLast(new LeveledFile(new File("./"), 1));
while(!stack.isEmpty()) {
LeveledFile current = stack.removeLast();
System.out.println(current.getFile());
if(current.getLevel() < maxLevel && current.getFile().isDirectory())
for(File child : current.getFile().listFiles())
stack.addLast(new LeveledFile(child, current.getLevel() + 1));
}
}
}