import java.io.*; public class FileList { public static void main(String[] args) { File f = new File("d:/java/A"); System.out.println(f.getName()); tree(f, 0); } private static void tree(File file, int level) { File[] fileList = file.listFiles(); String preStr = ""; for(int i=0; i<level; i++) { preStr += " "; } for(int i=0; i<fileList.length; i++) { System.out.println(preStr + fileList[i].getName()); if(fileList[i].isDirectory()) { tree(fileList[i], level + 1); } } } }