//Hadoop计算文件大小:
public static void main(String[] args) throws IOException{
String tablePath= pathPrefix + args[0].toLowerCase().trim();
Path p = new Path(tablePath);
JobConf conf= new JobConf();
FileSystem fs = p.getFileSystem(conf);
for(FileStatus f : fs.listStatus(p)){
if(f.isDir()){
long len = 0L;
for(FileStatus file: fs.listStatus(f.getPath())){
len = len + file.getLen();
}
System.out.println(f.getPath().toString().replace(pathPrefix, "")
.replace(args[0].toLowerCase().trim(), "")+" size: "+ len/1024/1024+" MB");
}
}
}
private static final String pathPrefix = "hdfs://hdpnn:9000/group/alibaba-dw-icbu/hive/";