递归算法算出某个目录下所有目录和文件

public class $ { 
    public static void main(String[] args) { 
        String path = "D:\\111"; 
        test(path); 
    }    
private static void test(String path) { File f = new File(path); File[] fs = f.listFiles(); if (fs == null) { return; } for (File file : fs) { if (file.isFile()) { System.out.println(file.getPath()); } else { test(file.getPath()); } } } }

猜你喜欢

转载自www.cnblogs.com/zhangxiong-tianxiadiyi/p/10853382.html