java读取系统Properties代码实例-创新互联-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java读取系统Properties代码实例-创新互联

这篇文章主要介绍了java 读取系统Properties代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

为田东等地区用户提供了全套网页设计制作服务,及田东网站建设行业解决方案。主营业务为成都做网站、网站设计、外贸营销网站建设、田东网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

java读取系统Properties 属性,针对配置较多的属性值,单独打印,实现代码如下:

import java.util.*;
 
public class PropertiesTest {
 
  public static void main(String[] args) {
 
    Properties properties = System.getProperties();
    PropertiesTest pt = new PropertiesTest();
    Map map = pt.getSpecialMap(properties);
    //便于方便读取,配置较多的属性打印出来
    pt.showMap(map);
  }
 
 
  Map getSpecialMap(Properties properties){
 
    Set> props = properties.entrySet();
    Map map = new HashMap();
    Iterator> it = props.iterator();
    while (it.hasNext()) {
      Map.Entry entry = it.next();
      System.out.println("key= " + entry.getKey() );
      System.out.println("value= " + entry.getValue());
      if("java.library.path".equalsIgnoreCase("" + entry.getKey())) {
        map.put(entry.getKey()+"",entry.getValue()+"");
      }
      if("java.class.path".equalsIgnoreCase("" + entry.getKey())) {
        map.put(entry.getKey()+"",entry.getValue()+"");
      }
      if ("sun.boot.class.path".equalsIgnoreCase("" + entry.getKey())) {
        map.put(entry.getKey()+"",entry.getValue()+"");
      }
      if("java.ext.dirs".equalsIgnoreCase("" + entry.getKey())) {
        map.put(entry.getKey()+"",entry.getValue()+"");
      }
    }
    return map;
  }
 
 
  void showMap(Map map) {
    for (Map.Entry entry : map.entrySet()) {
      System.out.println("----------------------------------------------------");
      System.out.println(entry.getKey() +":");
      splitStr(entry.getValue());
      System.out.println("----------------------------------------------------");
    }
  }
 
  void splitStr(String string) {
    String[] str = string.split(";");
    for (int i = 0; i < str.length; i++) {
      System.out.println(str[i]);
    }
  }
}

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


名称栏目:java读取系统Properties代码实例-创新互联
URL标题:http://scgulin.cn/article/pgcep.html