Property Files and Properties class
Hi,
My Property file:
base.dir=D:/Test
src=${base.dir}/src
classes=${base.dir}/classes
I am using the following code to read it:
Properties properties =new Properties();
FileInputStream fis =new FileInputStream(propertiesFile);
properties.load(fis);
Enumeration keys = properties.propertyNames();
while (keys.hasMoreElements()){
String key = (String) keys.nextElement();
String value = properties.getProperty(key);
System.out.println("key:" + key +"-value:" + value);
}
I get the following output:
key:base.dir-value:D:/Test
key:src-value:${base.dir}/src
key:classes-value:${base.dir}/classes
I anticipated
key:base.dir-value:D:/Test
key:src-value:D:/Test/src
key:classes-value:D:/Test/classes
Please help!
Thanks
VSR
# 1
This is not the right forum to ask this question.
http://forum.java.sun.com/ann.jspa?annID=14
Your assumption that Java will substitute value of ${base.dir} for src and classes is invalid. Please read : http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html
You will have to write your own code to substitute value of base.dir into other properties.
It might also help you to explore capabilities of a Java Build tool called ANT.
-Prashant
# 2
Yes, I am aware of the fact Prashant.
We don't have a forum for 'Java Utils', do we?
And I can't post this matter in Java Collections, either.
But it is totally out of topic, if we look at it as Ant doing it?
How Ant does, may still be Java using Properties class?
Anyway,
How is it done? Any thoughts?
Thanks
# 3
You should post your question in the Java Beginner's forums. This forum is about Generics, and by posting here you might miss the guys who are interested in more general questions like properties, ant, etc.
dit: sorry, I meant Java Essentials, not Beginners.