可以用bin/hadoop fs -ls 来读取HDFS某一目录下的文件列表及属性信息。
也可以采用HDFS的API来读取。如下:
import ;
import ;
import ;
import ;
import ;
import ;
public class FilesList
{
public static void main(String[] args) throws Exception
{
if( != 1){
("Usage : FilesList <target>");
(1);
}
Configuration conf = new Configuration();
FileSystem hdfs = ((args[0]),conf);
FileStatus[] fs = (new Path(args[0]));
Path[] listPath = FileUtil.stat2Paths(fs);
for(Path p : listPath)
(p);
}
}