我正在编写一个小程序来使用Java加载HDFS文件。运行代码时,我从HDFS获取文件列表。但是,我想单独获取分区文件。例如,part-00000文件。
以下是示例代码:
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://localhost");
FileSystem hdfs = FileSystem.get(new URI(
"hdfs://localhost"), conf);
RemoteIterator<LocatedFileStatus> fsStatus = hdfs.listFiles(
new Path("/hdfs/path"), true);
while (fsStatus.hasNext()) {
String path = fsStatus.next().getPath().toString();
System.out.println(path.matches("part-"));
}
我假设您要打印该路径,而不是它匹配
的事实if (path.startsWith("part-")) {
System.out.println(path);
}