1 2 1

文件详情查看

  1 //文件详情查看
  2 @Test
  3 public void testListFiles() throws IOException, InterruptedException, URISyntaxException {
  4 
  5 	//获取文件系统
  6 	Configuration configuration = new Configuration();
  7 	FileSystem fs = FileSystem.get(new URI("hdfs://192.168.12.161:9000"), configuration, "hadoop");
  8 	//获取文件详情
  9 	RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);
 10 	while(listFiles.hasNext()) {
 11 		LocatedFileStatus filestatus = listFiles.next();
 12 		//输出详情
 13 		//文件名称
 14 		System.out.println(filestatus.getPath().getName());
 15 		//文件长度
 16 		System.out.println(filestatus.getLen());
 17 		//文件权限
 18 		System.out.println(filestatus.getPermission());
 19 		//分组
 20 		System.out.println(filestatus.getGroup());
 21 		//获取存储信息
 22 		BlockLocation[] blockLocations = filestatus.getBlockLocations();
 23 		for (BlockLocation blockLocation : blockLocations) {
 24 			//获取块存储的主机节点
 25 			String[] hosts = blockLocation.getHosts();
 26 			for (String host : hosts) {
 27 				System.out.println(host);
 28 			}
 29 		}
 30 		System.out.println("------------这是一条分割线-------------");
 31 	}
 32 	//关闭资源
 33 	fs.close();
 34 }
posted @ 2019-10-08 15:41  NotFound-404  阅读(110)  评论(0)    收藏  举报