标签:buffer tst evel 测试 imp sys repeat pen out
1 import java.io.File; 2 3 public class ListFile { 4 private File root; 5 6 public ListFile(String path) { 7 this.root = new File(path); 8 } 9 10 public void list() { 11 this.list(this.root, 0); 12 } 13 14 private void list(File file, int level) { 15 for (File f : file.listFiles()) { 16 System.out.println(this.repeatStr(level) + f.getName()); 17 if (f.isDirectory()) { 18 this.list(f, level + 1); 19 } 20 } 21 } 22 23 private String repeatStr(int level) { 24 StringBuffer buffer = new StringBuffer(); 25 for (int i = 0; i < level; i++) { 26 buffer.append("-"); 27 } 28 return buffer.toString(); 29 } 30 31 public static void main(String[] args) { 32 ListFile file = new ListFile("./"); 33 file.list(); 34 } 35 }
123 | 321 |
456 | 654 |
标签:buffer tst evel 测试 imp sys repeat pen out
原文地址:https://www.cnblogs.com/horvey/p/10149470.html