public static void main(String[] args) { // TODO Auto-generated method stub //方法名、参数名小写开头 类名大写开头 // ../获取相对路径 printFiles(new File("../helloFile"),1); } public static void printFiles(File file,int tab) { if(file.isDirectory()) { File next[]=file.listFiles(); for (int i = 0; i < next.length; i++) { for (int j = 0; j < tab; j++) { System.out.print("|---"); } System.out.println(next[i].getName()); if(next[i].isDirectory()) { printFiles(next[i],tab+1); } } } }