Hi,
I am trying to read from a property file using the following code. I
dont get the value for "name" key. So I tried to read the number of
keys in the file, that too return 0. Could you please help me.
Code:
----------
static String rateFinder()
{
int elen=0;
Properties props=new Properties();
try
{
props.load( new FileInputStream(new File("test.properties")));
}
catch(IOException ie)
{
System.out.println("Error reading file");
}
// String key = "name";
// String val = props.getProperty(key,"notfound");
Enumeration enum = props.keys();
while(enum.hasMoreElements())
{
elen+=1;
}
return Integer.toString(elen);
}
test.properties
----------------------
name=subi
roll=101
mark1=100
*****
Both the files are in same location, indeed i do not get IOException.
It seems the method reads the file but not the contents. Pls help.
Thanks,
subi.
subi - 30 Dec 2005 07:42 GMT
I have to use static method as i read the returned value in a legacy
method which should take only static values.
Thanks,
Subi
Roedy Green - 30 Dec 2005 09:21 GMT
>props.load( new FileInputStream(new File("test.properties")));
Java is going to look in the CWD for test.properties. Dump out the
CWD to make sure it is looking in the right place. See
http://mindprod.com/jgloss/cwd.html
Also see http://mindprod.com/jgloss/properties.html
to make sure your properties file has the correct format.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.