HDFS的Java客户端操作代码(查看HDFS下所有的文件存储位置信息)
2024-10-16 11:29:30
1.查看HDFS下所有的文件存储位置信息
package Hdfs; import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; public class LocationFile {
public static void main(String[] args) throws Exception {
String uri = "hdfs://neusoft-master:9000/user/root/test/demo1";
Configuration conf = new Configuration();
try {
FileSystem fs = FileSystem.get(URI.create(uri), conf);
Path fpath = new Path(uri);
FileStatus fileStatus = fs.getFileStatus(fpath);
BlockLocation[] blockLocations = fs.getFileBlockLocations(
fileStatus, 0, fileStatus.getLen());
int blocklen = blockLocations.length;
for (int i = 0; i < blocklen; i++) {
String[] hosts = blockLocations[i].getHosts();
System.out.println("block_" +i+ "_location:" + hosts[0]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
HDFS下所有文件存储位置
2.提交jar包,并分析运行结果
3.这里的显示结果:
block_0_location:neusoft-master
分别为:块号:主机名,因为HDFS的文件是由Data块完成的,Hadoop中得block块一般64M
Hadoop2中block块为128M。(单独分析block块)
最新文章
- Eclispe远程调试tomcat设置
- html5 canvas 实现倒计时 功能
- 加载 CSS 时不影响页面渲染
- js判断手机访问web网站跳转到手机版
- JDBC操作Oracle数据库——实际操作过程中的小总结
- mouseover和this的巧用
- .NET开发微信小程序-获取OpenId
- MYSQL可调用执行自定义SQL的代码
- Ireport启动错误
- 什么是crf
- 利用Java获取ip地址
- C#反射类中所有字段,属性,方法
- 学习笔记15—Python 存储集
- Oracle VirtualBox添加虚拟机
- 远程訪问路由器下的mac os(ssh+vnc)
- 每日英语:Asia Has World&#39;s Biggest Pay Gap, Study Finds
- CSS3——transform2D的应用
- Delphi单元文件之-简体繁体互转
- UVa 10245 The Closest Pair Problem (分治)
- C#编译问题'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument
热门文章
- LeetCode(2) || Add Two Numbers &;&; Longest Substring Without Repeating Characters
- codeforces D. Count Good Substrings
- 5个提升Google Chrome浏览器运行速度的技巧
- poj1150
- WordPress wp-includes/functions.php脚本远程任意代码执行漏洞
- 【转】ButterKnife基本使用--不错
- 制作手机浏览器显示格式的HTML页面
- APP界面设计之页面布局的22条基本原则
- 495. Kids and Prizes
- 4G