Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

probelm in properties

Thread view: 
subi - 30 Dec 2005 07:40 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.