我正在尝试使用 Java API 访问 HDFS 中的文件,但每次我得到文件未找到。我用来访问的代码是:-
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);
}
这是代码的命令行输出。
[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
我是hadoop的新手,所以我不知道出了什么问题。