package com.lango.mapreduce.example.chainmapper;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Test {
public static void main(String[] args) throws IOException {
String INPUT_PATH = "/access_data";
Test.iterFs(INPUT_PATH);
}
private static void iterFs(String INPUT_PATH) throws IOException {
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://master:9000");
FileSystem hdfs = FileSystem.get(conf);
Path listf = new Path(INPUT_PATH);
FileStatus stats[] = hdfs.listStatus(listf);
for(FileStatus f : stats){
String fsPath = f.getPath().toString();
System.out.println(fsPath);
if(f.isDir()){
iterFs(fsPath);
} else {
System.out.println(fsPath);
}
}
}
}
转载于:https://my.oschina.net/HIJAY/blog/300435