The reason this points to your local file system is that core-site.xml and hdfs-site.xml not added properly. The code snippet below will help you.
Configuration conf = new Configuration(); conf.addResource(new Path("file:///etc/hadoop/conf/core-site.xml")); // Replace with actual path conf.addResource(new Path("file:///etc/hadoop/conf/hdfs-site.xml")); // Replace with actual path Path pt = new Path("."); // HDFS Path FileSystem fs = pt.getFileSystem(conf); System.out.println("Home directory :"+fs.getHomeDirectory());
Update:
An option should work, It seems there are some problems in the configuration file or path. You have another option, instead of adding configuration files using the addResource method, use the set method. Open core-site.xml and look for fs.defaultFS . Use the set method instead of the addResource method.
conf.set("fs.defaultFS","hdfs://<Namenode-Host>:<Port>");
source share