Procedure: Using properties files in Java

1 About this document

This document outlines a few unofficial steps on implementing properties files in a Java web application using Eclipse as the IDE. In this case we are on a Unix based OS.
Java developers using Eclipse
Eclipse IDE
This version date

02/21/09 09:55:26 AM

2 Create a properties file and save it in your Classpath = tim
user.password = mypassword
more.stuff = thisandthat

3 Code for the Servlet to initialize the properties class

String userPropertiesFile = /this_file.txt;
Properties prop = new Properties();
        try {
        } catch (Exception e) {
            System.out.println("Unable to load Properties file" + e);

4 Code for servlet to obtain values

String password = prop.getProperty("user.password", "defaultValue"));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s