public class DirList {
public static void main(String[] args) throws IOException {
File currentDir = new File(".");
listDir(currentDir.getCanonicalFile(), 0);
}
static void listDir(File dir, int level) {
File[] fs = dir.listFiles();
if (fs != null) {
for (File f : fs) {
if (f.isDirectory()){
printSpace(level);
System.out.println(f.getName() + "/");
listDir(f, level + 1);
}else{
System.out.println(f.getName());
static void printSpace(int level){
for(int i = 0; i < level; i++){
System.out.print(" ");
Sign in to make a reply
Andylbc
public class DirList {
public static void main(String[] args) throws IOException {
File currentDir = new File(".");
listDir(currentDir.getCanonicalFile(), 0);
}
static void listDir(File dir, int level) {
File[] fs = dir.listFiles();
if (fs != null) {
for (File f : fs) {
if (f.isDirectory()){
printSpace(level);
System.out.println(f.getName() + "/");
listDir(f, level + 1);
}else{
printSpace(level);
System.out.println(f.getName());
}
}
}
}
static void printSpace(int level){
for(int i = 0; i < level; i++){
System.out.print(" ");
}
}
}