Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to read a Java properties file on HDFS

How to read a Java properties file on HDFS

Expert Contributor

I got a properties file that I want to read from HDFS and here is what I have right now:

 

try {    properties.load(new FileInputStream("hdfs://user/hdfs/my_props.properties"));
} catch (IOException e) {
    throw new RuntimeException("Properties file not found.");
}

But I run into "Properties file not found" exception. It works fine if I attempt to read a local file. How do I go about reading a file on HDFS in Java?

 

Thanks!

1 REPLY 1

Re: How to read a Java properties file on HDFS

Master Guru
} catch (IOException e) {
    throw new RuntimeException("Properties file not found.");
}

You're swallowing the real error, which would tell you more on why it fails. Have you tried to print e's original stack trace to see what the issue is?

 

I think Chapter 2 or 3 in Hadoop: The Definitive Guide talks about how you can register a hdfs:// URI handler in Java to be able to use some standard Java APIs to read HDFS URI files. If thats not a limitation, check and use the FileSystem classes directly [1].

 

[1] - FileSystem