static void listDir(File dir, int i) throws IOException { // TODO: 递归打印所有文件和子文件夹的内容 File[] fs = dir.listFiles(); String delimiter = ""; for (int j = 0; j<i; j++) { delimiter += " "; } if (fs != null) { for (File f : fs) { String file_tmp = delimiter + f.getName(); if (f.isDirectory()) { System.out.println(file_tmp+"/"); listDir(f.getCanonicalFile(), i+1); } else { System.out.println(file_tmp); } } }}
Sign in to make a reply
jasmine