开发者

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

开发者 https://www.devze.com 2023-04-12 17:48 出处:网络
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 addr

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

精彩评论

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