1、Code -> GitHub
https://github.com/liufengji/hadoop_hdfs.git
2莫湘、Code
//查看文件名稱倾鲫、權(quán)限粗合、長度萍嬉、塊信息
@Test
public void readListFiles() throws Exception {
// 1 創(chuàng)建配置信息對象
Configuration configuration = new Configuration();
FileSystem fs = FileSystem.get(new URI("hdfs://node1:9000"),configuration, "victor");
RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);
while (listFiles.hasNext()) {
LocatedFileStatus fileStatus = listFiles.next();
System.out.println(fileStatus.getPath().getName());
System.out.println(fileStatus.getBlockSize());
System.out.println(fileStatus.getPermission());
System.out.println(fileStatus.getLen());
BlockLocation[] blockLocations = fileStatus.getBlockLocations();
for (BlockLocation bl : blockLocations) {
System.out.println("block-offset:" + bl.getOffset());
String[] hosts = bl.getHosts();
for (String host : hosts) {
System.out.println(host);
}
}
System.out.println("--------------分割線--------------");
}
}