用递归的方式得出C盘下所有文件

public static void main(String[] args) {
        File file = new File("C:\\");
        test(file);
    }
    
    
    public static void test(File file) {
        File[] fileArr = file.listFiles();
        if(fileArr != null) {
            for (File string : fileArr) {
                if(string.isDirectory() ) {
                    test(string);
                }else {
                    // 输出文件名
                    System.err.println(string.getName());
                    // 输出文件的路径
                    System.out.println(string.getPath());
                }
            }
            
        }
        
    }

猜你喜欢

转载自blog.csdn.net/Mr_Wu__/article/details/81094272