HadoopHelper使用说明
生活随笔
收集整理的這篇文章主要介紹了
HadoopHelper使用说明
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
HadoopHelper使用說明
@(HADOOP)[hadoop]
1、獲取某個(gè)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; }總結(jié)
以上是生活随笔為你收集整理的HadoopHelper使用说明的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在hadoop中传递变量
- 下一篇: REST、SOAP、protocolbu