New Contributor
Posts: 3
Registered: ‎09-30-2016

Not able to create a directory in HDFS



I have the following code to create a directory in HDFS. The code is running smoothly and not throwing any exception, but it is nither creating a directory nor throwing exception. And surprising thing is i am able to create the directory using hadoop fs commands.


I am using the cloudera version - CDH-5.9.0-1.


public static void main(String[] args) throws Exception {
        if (conf == null) {
            conf = new Configuration();
            conf.addResource(new Path("/etc/hadoop/conf.cloudera.hdfs/core-site.xml"));
            conf.addResource(new Path("/etc/hadoop/conf.cloudera.hdfs/hdfs-site.xml"));
        hdfs = FileSystem.get(conf);
        if (!hdfs.exists(new Path(hdfsPath))) {
            boolean status = hdfs.mkdirs(new Path(hdfsPath));
            if (status) {
                System.out.println("Dir created successfully.");
            } else {
                System.out.println("Failed to create Dir.... Status: " + status);
        } else {
			System.out.println("Directory already exist..!");


Output:    Failed to create Dir.... Status: false



Note: I have verified the xml files are available and having full permissions for current user from which the code is running. (Also, the directory which i am trying to create is not exist before running the code).


Please let me know the reason why it is not creating the directory and atleast why it is not throwing exception message.


Thanks in advance.