java.util.Properties - set a default value

Hi,

the following code shows the problem. I read in a properties file which has

the entry:

KeyA=

Now, i want to give out the default value, if no value is set as it is the case above. But the output is nothing. What磗 the problem and how to solve it?

import java.io.*;

import java.util.*;

publicclass Test{

public Test(){

test();

}

privatevoid test(){

Properties props =new Properties();

try{

props.load(new FileInputStream("props.properties"));

}catch(IOException ioe){ioe.printStackTrace();}

System.out.println(props.getProperty("KeyA","defaultValue"));

}

publicstaticvoid main(String args[]){

new Test();

}

}

Thanks for answers in advance!

[1673 byte] By [Cinimooda] at [2007-11-27 2:36:54]
# 1
The problem is that your key obviously has a value, namely the empty String. The default is provided if the key is not defined at all.
CeciNEstPasUnProgrammeura at 2007-7-12 2:56:37 > top of Java-index,Java Essentials,Java Programming...
# 2
The default value is shown if the key is not found. In this example, the key is found, but its value is the empty string.Edit: Man. It took forever to load the "reply" page so my response looks really slow.
masijade.a at 2007-7-12 2:56:37 > top of Java-index,Java Essentials,Java Programming...