gpt4 book ai didi

java - 无法列出hadoop中的文件

转载 作者:可可西里 更新时间:2023-11-01 14:31:59 26 4
gpt4 key购买 nike

我是 hadoop 新手。

我正在尝试使用此递归代码列出我的 hdfs 中存在的所有文件。

public void list(String path) throws IOException {
Path dirPath = new Path(path);
FileStatus[] fileStatus = fileSystem.listStatus(dirPath);
if(fileStatus != null) {
for (FileStatus fs : fileStatus) {
String name = fs.getPath().getName();
if(fs.isDir()) {
System.out.println("dir --> " + name);
list(dirPath.getName() + "/" + name);
} else {
System.out.println("file --> " + name);
}
}
}
}

但是我没有得到文件列表。

提前致谢..

最佳答案

如前所述,您必须正确初始化文件系统对象。它应该是这样的:

Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);

如果您尝试从 HDFS 获取数据,uri 应该包含 hdfs:/// 前缀。

关于java - 无法列出hadoop中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747997/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com