probelm in properties

Discussion in 'Java' started by subi, Dec 30, 2005.

  1. subi

    subi Guest

    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, Dec 30, 2005
    #1
    1. Advertising

  2. subi

    subi Guest

    I have to use static method as i read the returned value in a legacy
    method which should take only static values.

    Thanks,
    Subi
     
    subi, Dec 30, 2005
    #2
    1. Advertising

  3. subi

    Roedy Green Guest

    On 29 Dec 2005 23:40:18 -0800, "subi" <> wrote,
    quoted or indirectly quoted someone who said :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Dec 30, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,020
    David Binnie
    Mar 17, 2006
  2. Grey
    Replies:
    0
    Views:
    300
  3. Benjamin Bittner

    Probelm with embed server controls

    Benjamin Bittner, Jul 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,525
    Benjamin Bittner
    Jul 7, 2004
  4. Mohamed Zaki

    Dropdown viewstate probelm

    Mohamed Zaki, Jul 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    415
    Mohamed Zaki
    Jul 13, 2004
  5. Davide Vernole [MVP]

    Re: UserControl Probelm

    Davide Vernole [MVP], Sep 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    410
    Davide Vernole [MVP]
    Sep 9, 2004
Loading...

Share This Page