1. import java.util.*;  

  2. /* 导入System类*/  

  3. class SystemProperties  

  4.     {   

  5.         public static void main(String[] args)  

  6.         { Properties pro = System.getProperties();   

  7.      //查阅API可知,Properties是Hashtable的子类,也是Map集合的子类   

  8.      //可以通过Map的方法去取出该集合的元素   

  9.      //Properties类存储的都是字符串,没有泛型定义   

  10.      //用foreach来遍历所有元素   

  11.      for(Object obj:pro.keySet())   

  12.      {   

  13.        String value = (String)prop.get(obj);    

  14.        System.out.println(obj+"::"+value);  

  15.      }   

  16.      //获取指定属性信息  

  17.      String value = System.getProperty("os.name");  

  18.      System.out.println("os.name="+value);  

  19.      //在系统中定义一些特有属性  

  20.      System.setProperty("MyKey","MyValue");  

  21.    }  

  22.  }