开发者

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

In my eclipse pr开发者_如何学Coject 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


  • java.util.Properties.store(..) to save
  • java.util.Properties.load(..) to load


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) {
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜