遍历HDFS中的文件
//使用API进行遍历
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS","hdfs://node01:8020");
//get方法从con中获取fs.defaultFS的值判断是什么类型的文件系统对象,如果不做配置,默认为本地系统文件对象
FileSystem fileSystem = FileSystem.get(configuration);
System.out.println(fileSystem.toString());
//获取Iterator得到相应的文件或者文件夹,第一个参数值的是路径,第二个参数表示是否要递归遍历
RemoteIterator<LocatedFileStatus> iterator = fileSystem.listFiles(new Path("/"), true);
while (iterator.hasNext()){
LocatedFileStatus next = iterator.next();
System.out.println(next.getPath().toString());
}
HDFS上创建文件夹
FileSystem fileSystem = FileSystem.get(new URI("hdfs://node01:8020"), new Configuration());
boolean mkdirs = fileSystem.mkdirs(new Pat