I am trying to access a file in the HDFS using Java APIs, but everytime I am getting File Not Found. Code which I am using to access is :-
Configuration conf = new Configuration();
conf.addResource(FileUtilConstants.ENV_HADOOP_HOME + FileUtilConstants.REL_PATH_CORE_SITE);
conf.addResource(FileUtilConstants.ENV_HADOOP_HOME + FileUtilConstants.REL_PATH_HDFS_SITE);
try {
FileSystem fs = FileSystem.get(conf);
Path hdfsfilePath = new Path(hdfsPath);
logger.info("Filesystem URI : " + fs.getUri());
logger.info("Filesystem Home Directory : " + fs.getHomeDirectory());
logger.info("Filesystem Working Directory : " + fs.getWorkingDirectory());
logger.info("HDFS File Path : " + hdfsfilePath);
if (!fs.exists(hdfsfilePath)) {
logger.error("File does not exists : " + hdfsPath);
}
And here is the command line output from the code.
[root@koversevms ~]# java -jar /tmp/thetus-incendiary-koverse-extension-fileutils-1.0-SNAPSHOT.jar
13/07/10 02:47:18 INFO fileutils.HadoopFileChecksumUtils: Filesystem URI : file:///
13/07/10 02:47:18 INFO fileutils.HadoopFileChecksumUtils: Filesystem Home Directory : file:/root
13/07/10 02:47:18 INFO fileutils.HadoopFileChecksumUtils: Filesystem Working Directory : file:/root
13/07/10 02:47:18 INFO fileutils.HadoopFileChecksumUtils: HDFS File Path : /usr/hadoop/sample/sample.txt
13/07/10 02:47:18 ERROR fileutils.HadoopFileChecksumUtils: File does not exists : /usr/hadoop/sample/sample.txt
I am new to hadoop so I don't know what is going wrong.
Here is code fragment originally posted in context of answer to this question. It should solve your question too despite intention of original question was different. Main point in your code is you have issues starting from scheme (
file://
). Please checkfs.defaultFS
variable in your configuration.