小编给大家分享一下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如何检索文件和目录相关信息”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。