import java.io.File; public class Test { public static void main(String[] args) { File file = new File("D:\\Documents"); printFile(file); } public static void printFile(File file) { String[] str = file.toString().split("\\\\"); System.out.println("-" + str[str.length - 1]); printFile(file, 1); } private static void printFile(File path, int level) { File[] files = path.listFiles(); if(files == null) { return; } for(File file: files) { for(int i = 0 ; i < level; i++) { System.out.print(" "); } String[] str = file.toString().split("\\\\"); System.out.println("-" + str[str.length - 1]); if(file.isDirectory()) { printFile(file, level + 1); } } } }
Sign in to make a reply
牛肉板面没有肉