TechnocraT
TechnocraT

Reputation: 313

java: how to add values to properties file and access them in program

In my eclipse project i have ip address string variable in many java class files, few jsps and also in context.xml file. I want to create a kind .properties file and declare this ip address as key value pair and access from all the classes from this particular file.How do i achieve this?

Regards TT

Upvotes: 0

Views: 1389

Answers (2)

Bozho
Bozho

Reputation: 597106

Upvotes: 2

Saket
Saket

Reputation: 46137

Use something like this:

// Read properties file.
Properties properties = new Properties();
try {
    properties.load(new FileInputStream("filename.properties"));
    String value = properties.getProperty("propertyKey");
} catch (IOException e) {
}

Upvotes: 0

Related Questions