HDFS FileStatus如何检索文件和目录相关信息

小编给大家分享一下HDFS FileStatus如何检索文件和目录相关信息,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

package com.lango.mapreduce.example.chainmapper;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Test {
    public static void main(String[] args) throws IOException {
        String INPUT_PATH = "/access_data";
        Test.iterFs(INPUT_PATH);
    }
    
    private static void iterFs(String INPUT_PATH) throws IOException {

        Configuration conf = new Configuration();
        conf.set("fs.default.name", "hdfs://master:9000");
        FileSystem hdfs = FileSystem.get(conf);
        
        Path listf = new Path(INPUT_PATH);
        FileStatus stats[] = hdfs.listStatus(listf);
        
        for(FileStatus f : stats){
            String fsPath = f.getPath().toString();
            System.out.println(fsPath);
            if(f.isDir()){
                iterFs(fsPath);
            } else {
                System.out.println(fsPath);
            }
        }
    }
}

看完了这篇文章,相信你对“HDFS FileStatus如何检索文件和目录相关信息”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!