标签:
System类
访问系统属性 - 遍历
1 package org.zln.usefulclass.system; 2 3 import java.util.Properties; 4 5 /** 6 * Created by sherry on 000024/6/24 23:08. 7 */ 8 public class TestSystemProperty { 9 public static void main(String[] args) { 10 //showSystemProperties(); 11 /*获取某个系统属性*/ 12 System.out.println(System.getProperty("java.version")); 13 } 14 15 /** 16 * 遍历系统所有属性 17 */ 18 private static void showSystemProperties() { 19 Properties properties = System.getProperties(); 20 properties.list(System.out); 21 } 22 }
遍历环境变量
1 /** 2 * 遍历环境变量 3 */ 4 public static void showEnvProperties(){ 5 Map<String,String> map = System.getenv(); 6 Iterator<String> iterator = map.keySet().iterator(); 7 while (iterator.hasNext()){ 8 String k = iterator.next(); 9 String v = map.get(k); 10 System.out.println(k+":"+v); 11 } 12 }
标签:
原文地址:http://www.cnblogs.com/sherrykid/p/4598962.html