[英]Load hdfs partitions files list
I am writing a small program to load hdfs files using java. 我正在编写一个小程序来使用java加载hdfs文件。 When i run the code, i get the list of files from the hdfs.
当我运行代码时,我从hdfs获取文件列表。 But, i want to get the partition files alone.
但是,我想单独获取分区文件。 Eg.part-00000 files.
例如,部分00000文件。
Below is the sample code: 以下是示例代码:
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-"));
}
I assume you want to print that path, not the fact that it matches 我假设您要打印该路径,而不是它匹配的事实
if (path.startsWith("part-")) {
System.out.println(path);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.