HDFS_API文件详情查看
代码:
private FileSystem fs;@Beforepublic void init() throws URISyntaxException, IOException {URI uri = new URI("hdfs://master:9000");// 创建一个配置文件Configuration entries = new Configuration();// 获取到了客户端对象
// entries.set("dfs.replication","2");fs = FileSystem.get(uri, entries);}@Testpublic void fileDetail() throws Exception{// 获取所有信息RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/sanguo"),false);int cnt = 0;System.out.println("Permission"+"\t"+"Owner"+"\t"+"Group"+"\t"+"Len"+"\t"+"ModificationTime"+"\t"+"Replication"+"\t"+"BlockSize"+"\t"+"PathName"+"\t"+"BlockInfo");// listFileswhile (listFiles.hasNext()) {LocatedFileStatus fileStatus = listFiles.next();BlockLocation[] blockLocations = fileStatus.getBlockLocations();System.out.println(fileStatus.getPermission()+"\t"+fileStatus.getOwner()+"\t"+fileStatus.getGroup()+"\t"+fileStatus.getLen()+"\t"+fileStatus.getModificationTime()+"\t"+fileStatus.getReplication()+"\t"+fileStatus.getBlockSize()+"\t"+fileStatus.getPath().getName()+"\t"+Arrays.toString(blockLocations));}}
}
效果: