Results 1 to 5 of 5
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default Taking input from Properties File

    I have written an application which needs input from user. I was thinking about my options. XML is an option but I don't want to use that.

    Can I use properties file for the input? Is it a good way of using properties file in Java or it has some other use?

    Thanks for looking into this.

  2. #2
    Sreejesh is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default Usage of property file

    You can use the property files when the application needs to get some values which are configured by the users.
    For eg, an anti virus application to scan the hard drive in a user defined schedule, user is able to change the schedule interval in a peoperty file as,

    SCAN_INTERVAL_IN_HOURS = 10
    Here each time the application starts, it will read the value of the key "SCAN_INTERVAL_IN_HOURS".

  3. #3
    deenkar1984 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default input from property file

    hi can any one help me in hoe to read values from property file

  4. #4
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default Example

    Java Code:
    Properties properties = new Properties();
    properties.load(new FileInputStream( propertyFilepath ));
    Java Code:
    properties.getProperty(yourKey);

    is this what you wanted? :confused:
    i am the future

  5. #5
    deenkar1984 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    hi i write this code and it worked f9
    private String getProperty() {
    // TODO Auto-generated method stub
    Properties properties = new java.util.Properties();
    try {
    properties.load( ( this.getClass().getClassLoader().getResourceAsStre am( "application.properties" ) ));
    }
    catch (IOException e) {
    e.printStackTrace();
    }
    return properties.getProperty("SMTP_HOST");
    }

Similar Threads

  1. Reading a properties file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 05-06-2010, 05:17 PM
  2. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  3. How to getvalue from properties file into JSP
    By jaga in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-04-2008, 08:00 AM
  4. Taking input from console
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 04:47 PM
  5. doubt about language .properties file
    By tommy in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 02:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •