문제

I am trying to set properties for an oozieclient in java which are read from a properties file. The properties file has 10 odd properties. Is there a way I can set these properties all at once and not have to read each key value pair from the file and then set them for the oozieclient?

OozieClient wc = new OozieClient(http://something:1100/oozie);

Properties conf = wc.createConfiguration();
conf.setProperty("jobTracker",....);
conf.setProperty("nameNode",......);
.
.
.

Instead of this, is there a way in which i can read these values from a properties file and set the values all at once?

도움이 되었습니까?

해결책

You can read another property file and merge both:

OozieClient wc = new OozieClient("http://something:1100/oozie");

Properties conf = wc.createConfiguration();
Properties p = new Properties();
FileInputStream fis = new FileInputStream("myfile.properties");
p.load(fis);
conf.putAll(p);
fis.close(); // you still need to close the stream

With the file myfile.properties like:

jobTracker=foo
nameNode=bar

Take a look at the Javadoc for Properties

다른 팁

Check out the following API: Oracle Docs. The load() operations on Properties can be given a reference to the .properties FileInputSteam or FileInputReader , it will read out all key-value pairs into your Properties-object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top