import java.io.File; import java.util.*; public class Main { public static void main(String[] args) { File file = new File("C:\\Users"); printFile(file, 0); } static void printFile(File file, int level){ if (file.isDirectory()){ System.out.println(getIndent(level, ' ') + file.getName() + "/"); for (File f:file.listFiles()){ printFile(f, level + 1); } } else if (file.isFile()){ System.out.println(getIndent(level, ' ') + file.getName()); } } static String getIndent(int level, char ch){ char[] a = new char[level]; Arrays.fill(a, ch); return new String(a); } }
Sign in to make a reply
bzip2