// 显示文件信息 public void showAll() { File f = new File(path); if (f.exists() && f.isDirectory()) { System.out.println(f.getPath() + "\t<DIR>\t Start-------");
File[] files = f.listFiles(); // 返回抽象路径名数组
for (File f1 : files) { if (f1.isDirectory()) { MyDir dir = new MyDir(f1.getPath()); dir.showAll(); } else if (f1.isFile()) { System.out.println(f1.getPath()); } } System.out.println(f.getPath() + "\t<DIR>\t End-------\n"); } }
public static void main(String[] args) { MyDir dir = new MyDir("C:\\WINDOWS"); dir.showAll(); } }