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块)

最新文章

  1. Eclispe远程调试tomcat设置
  2. html5 canvas 实现倒计时 功能
  3. 加载 CSS 时不影响页面渲染
  4. js判断手机访问web网站跳转到手机版
  5. JDBC操作Oracle数据库——实际操作过程中的小总结
  6. mouseover和this的巧用
  7. .NET开发微信小程序-获取OpenId
  8. MYSQL可调用执行自定义SQL的代码
  9. Ireport启动错误
  10. 什么是crf
  11. 利用Java获取ip地址
  12. C#反射类中所有字段,属性,方法
  13. 学习笔记15—Python 存储集
  14. Oracle VirtualBox添加虚拟机
  15. 远程訪问路由器下的mac os(ssh+vnc)
  16. 每日英语:Asia Has World&#39;s Biggest Pay Gap, Study Finds
  17. CSS3——transform2D的应用
  18. Delphi单元文件之-简体繁体互转
  19. UVa 10245 The Closest Pair Problem (分治)
  20. C#编译问题'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument

热门文章

  1. LeetCode(2) || Add Two Numbers &amp;&amp; Longest Substring Without Repeating Characters
  2. codeforces D. Count Good Substrings
  3. 5个提升Google Chrome浏览器运行速度的技巧
  4. poj1150
  5. WordPress wp-includes/functions.php脚本远程任意代码执行漏洞
  6. 【转】ButterKnife基本使用--不错
  7. 制作手机浏览器显示格式的HTML页面
  8. APP界面设计之页面布局的22条基本原则
  9. 495. Kids and Prizes
  10. 4G