import java.io.File; public class Test { /** * @param args * @author blog.ytso.com */ public static void main(String[] args) { File f = new File("F:/javaAPI/JavaAPI1.6/java/awt"); printFile(f, 0); } public static void printFile(File f, int len) { String str = ""; for (int i = 0; i < len; i++) { str += " "; // 路径空格,以便更好的展现层次结构 } File file[] = f.listFiles(); for (int i = 0; i < file.length; i++) { System.out.println(str + file[i].getName()); if (file[i].isDirectory()) { printFile(file[i], len + 1); } } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10587.html