`
superlxw1234
  • 浏览: 543248 次
  • 性别: Icon_minigender_1
  • 来自: 西安
博客专栏
Bd1c0a0c-379a-31a8-a3b1-e6401e2f1523
Hive入门
浏览量:43359
社区版块
存档分类
最新评论

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());
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics