11.14
1|12递归查看目录下的文件信息
/*查看当前目录下的文件信息*/
public static void printfile(String file)throws URISyntaxException, IOException, InterruptedException
{
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root");
FileStatus[] statuses=fs.listStatus(new Path(file));
for(FileStatus s:statuses)
{
System.out.println("读写权限:"+s.getPermission()+"; 文件大小:"+s.getBlockSize()+"; 文件路径:"
+s.getPath()+"; 文件创建时间:"+s.getModificationTime());
}
fs.close();
}
/*递归查看目录下的文件信息*/
public static void prinfileInfo(String file)throws URISyntaxException, IOException, InterruptedException
{
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root");
Path path= new Path(file);
RemoteIterator<LocatedFileStatus> iterator = fs.listFiles(path, true);
while(iterator.hasNext()) {
FileStatus s = iterator.next();
System.out.println("读写权限:"+s.getPermission()+"; 文件大小:"+s.getBlockSize()+"; 文件路径:"
+s.getPath()+"; 文件创建时间:"+s.getModificationTime());
}
fs.close();
}