HDFS获取目录大小API
来源:互联网 发布:telnet 内网ip 端口 编辑:程序博客网 时间:2024/05/19 13:56
获取文件大小,在命令行上,使用hadoop fs -du 命令可以,但是通过javaAPI怎么获取呢,
最开始我想到的是递归的方法,这个方法很慢,后来发现FileSystem.getContentSummary的方法
最慢的一个方法–递归
网上很多类似的方法,不建议
使用FileSystem.getContentSummary方法
下面是api的一句话:
The getSpaceConsumed() function in the ContentSummary class will return the actual space the file/directory occupies in the cluster i.e. it takes into account the replication factor set for the cluster.
For instance, if the replication factor in the hadoop cluster is set to 3 and the directory size is 1.5GB, the getSpaceConsumed() function will return the value as 4.5GB.
Using getLength() function in the ContentSummary class will return you the actual file/directory size.
示例代码如下
public static void main(String[] args) { FileSystem hdfs = null; Configuration conf = new Configuration(); try { hdfs = FileSystem.get(new URI("hdfs://192.xxx.xx.xx:9000"),conf,"username"); } catch (Exception e) { e.printStackTrace(); } Path filenamePath = new Path("/test/input"); try { //会根据集群的配置输出,例如我这里输出3G System.out.println("SIZE OF THE HDFS DIRECTORY : " + hdfs.getContentSummary(filenamePath).getSpaceConsumed()); // 显示实际的输出,例如这里显示 1G System.out.println("SIZE OF THE HDFS DIRECTORY : " + hdfs.getContentSummary(filenamePath).getLength()); } catch (IOException e) { e.printStackTrace(); } }
1 0
- HDFS获取目录大小API
- 通过获取HDFS目录/文件夹大小来控制reduce个数
- hdfs查看目录大小文件大小
- c# 获取目录大小
- hdfs查看各级目录文件的大小
- php获取某个目录大小
- php获取某个目录大小
- php获取某个目录大小
- php获取某个目录大小
- php获取某个目录大小
- php获取某个目录大小
- 获取指定目录的大小
- Windows下获取目录大小
- 获取目录下内容大小
- 获取屏幕大小的API
- API获取系统常用目录
- 文件路径获取目录API
- Java API 读取HDFS目录下的所有文件
- 算法训练 删除数组零元素
- Android---Handler机制总结
- Complex1
- 大家注意了,襄阳宏帆商务咨询有限公司是诈骗公司。
- 在一个app中打开另外一个app中的一个actiivty
- HDFS获取目录大小API
- sky3888 Top Up Joker Card of King of Chicago Slot Game
- eclipse常用快捷键
- 角谷猜想
- java垃圾回收机制(1)
- 利用TextureView来实现拍照功能
- sql 查询结果能当查询条件用的方式
- Shape文件导Mysql
- Java对象值传递和对象传递的总结