package chengbaoDemo; import java.io.File; import java.io.IOException; public class TestIOFile { public static void main(String[] args) { File f = new File("D:/Project/java/Test"); printTreeFile(f, 0); } public static void printTreeFile(File file, int level) { for (int i = 0; i < level; i++) { System.out.print("\t"); } String fileName = file.getName(); System.out.println(fileName); if (file.isDirectory()) { File[] files = file.listFiles(); for (File f: files) { printTreeFile(f, level + 1); } } } }
时间: 2024-12-17 08:07:08