//显示Hadoop文件系统中一组路径的文件信息 //我们可以用这个程序来显示一组路径集目录列表的并集 package com;
import java.io.IOException; import java.net.URI;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path;
public class ListStatus {
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String uri = args[0]; Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(uri), conf); Path[] paths = new Path[args.length]; for(int i = 0; i < paths.length; i ){ paths[i] = new Path(args[i]); } FileStatus[] status = fs.listStatus(paths); Path[] listedPaths = FileUtil.stat2Paths(status); for(Path p : listedPaths){ System.out.println(p);
} }
}