Querying HDFS File System


FileStatus:

Java API for Hadoop Distributed file system provides one important class org.apache.hadoop.fs.FileStatus for querying HDFS File System. This class encapsulates the file system meta data. We can obtain meta data about the files, directories, including file length, block size, replication, modification time, ownership, and permission information.

We can get the instance of FileStatus by calling getFileStatus() method on file system object.

Below are some of the important methods on FileStatus class.

Below is a sample program for illustrating the above methods of FileStatus class.

After compiling the above program and adding the class file location to HADOOP_CLASSPATH environment variable, then we can test the output of the program as shown below.

FileStatus1In the above screen shot, we can observe all the meta data (File length, Modification time, replication factor, block size and etc…) about hdfs://localhost:9000/input/word_input.txt file.