HadoopHelper使用说明

来源:互联网 发布:电信宽带免费提速软件 编辑:程序博客网 时间:2024/06/08 02:49

HadoopHelper使用说明

@(HADOOP)[hadoop]

1、获取某个HDFS目录的du大小

官方竟然没有提供API。

public long getDirSize(String dir) throws IOException {    Long blockSize = 0L;    FileSystem fs = FileSystem.get(URI.create(dir), _conf);    FileStatus[] stats =  fs.listStatus(new Path(dir));    if (stats==null || stats.length ==0) {            LOG.error("Cannot access " + dir +                 ": No such file or directory.");            throw new FileNotFoundException("Cannot access " + dir +                     ": No such file or directory.");         }      for(FileStatus stat: stats){        blockSize += stat.getLen();    }    return blockSize;}
原创粉丝点击