读书人

java api获取hdfs索引大小

发布时间: 2012-09-01 09:33:02 作者: rapoo

java api获取hdfs目录大小

1. hadoop fs -dus 的源码:

?

public static void dus(String src,Configuration conf) throws IOException {    Path srcPath = new Path(src);    FileSystem srcFs = srcPath.getFileSystem(conf);    FileStatus status[] = srcFs.globStatus(new Path(src));    if (status==null || status.length==0) {      throw new FileNotFoundException("Cannot access " + src +           ": No such file or directory.");    }    for(int i=0; i<status.length; i++) {      long totalSize = srcFs.getContentSummary(status[i].getPath()).getLength();      String pathStr = status[i].getPath().toString();      System.out.println(("".equals(pathStr)?".":pathStr) + "\t" + totalSize);    }  }

?

2.

FileSystem fs = new Path(s).getFileSystem(conf);System.out.println(fs.getContentSummary(new Path(s)).getLength());
?

读书人网 >互联网

热点推荐