Do You Need Help With Your Java Programming

download Do You Need Help With Your Java Programming

of 4

Transcript of Do You Need Help With Your Java Programming

  • 7/31/2019 Do You Need Help With Your Java Programming

    1/4

    Do you needhelp withyour Javaprogramming?Click herefor instanthelp withyour Javacode.

    Loading configuration parameters from textfile into a program

    Loading parameters into a program is easily handled in Java through the Properties class.The only thing that has to be done is to create an instance of the Properties class and one instanceFileInputStream class that points to the configuration file.The actual loading of the parameters are done through the method load() on the Properties object.In the example below parameters are read from the configuration file and then printed out.

    This is what the sample configuration file looks like:

    # System configuration

    # Comments will automatically be excluded by the program.

    parameter1=value1

    parameter2=value2

    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.io.IOException;

    import java.util.Enumeration;

    import java.util.Properties;

    /**

    * Main.java*

    * @author www.javadb.com

    */

    publicclass Main {

    Properties config;

    /**

    * Loads configuration parameters from a textfile and print them out.

    http://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/http://www.javadb.com/http://www.javadb.com/http://www.javadb.com/http://www.javadb.com/http://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/http://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/http://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_helphttp://www.javadb.com/loading-configuration-parameters-from-textfile-into-a-program#java_help
  • 7/31/2019 Do You Need Help With Your Java Programming

    2/4

    */

    publicvoid loadConfigFile() {

    //Load configuration file

    String filename = "conf/systemconfig.txt";

    config = new Properties();

    try {

    config.load(new FileInputStream(filename));

    } catch (FileNotFoundException ex) {

    ex.printStackTrace();return;

    } catch (IOException ex) {

    ex.printStackTrace();

    return;

    }

    //Print out the configuration parameters

    Enumeration en = config.keys();

    System.out.println("********** System configuration **********");while (en.hasMoreElements()) {

    String key = (String) en.nextElement();

    System.out.println(key + " => " + config.get(key));

    }

    }

    /**

    * Starts the program

    *

    * @param args the command line arguments

    */

    publicstaticvoid main(String[] args) {

    new Main().loadConfigFile();

    }

    }

    This is the output after printing out the loaded configuration parameters:

    ********** System configuration **********

    parameter2 => value2

    parameter1 => value1

    Do you know your Java?Take a Ten-Question-Java-Quiz!

    http://www.javadb.com/java-question-about-default-and-defined-constructorshttp://www.javadb.com/java-question-about-default-and-defined-constructorshttp://www.addthis.com/bookmark.php?v=250&pub=xa-4b1c24a54f5857bdhttp://www.javadb.com/java-question-about-default-and-defined-constructors
  • 7/31/2019 Do You Need Help With Your Java Programming

    3/4

    Search for code examples on this site

    Search

    Need help with your Java code? It's secure and confidential.

    This is how it works:

    Send a detailed description of what you need help with, the more details thebetter. Also provide a deadline for when it has to be finished. More time meanbetter chance of putting your request into the schedule.

    If the request is serious you will shortly receive an email with the price, to whicyou have to respond if you accept.

    Once you have accepted, the work will begin on developing your code by anexperienced Java developer. When the code is finished a link to a securepayment will be sent to you.

    The source code is then sent to you once the payment is completed.

    IMPORTANT! The request needs to be very detailed, else it may be ignored.

    Write your detailed request here:

    E-mail address:

  • 7/31/2019 Do You Need Help With Your Java Programming

    4/4

    Post Request

    [ Home ]

    Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.Javadb.com is independent of Sun Microsystems, Inc.

    2012 javadb.com

    http://www.javadb.com/http://www.javadb.com/