sysproperty.java

来自「此文档包含有AOP」· Java 代码 · 共 35 行

JAVA
35
字号
package test.property;

import java.util.Enumeration;

/**
 * #{System Property Test}
 * If you append the argment like "-Dname=wang" to the command "java.exe",
 * you will set the system's property named "name" with "wang"
 * 
 * Then , you can get the value of it as follows:
 * 	java.util.Properties property = System.getProperties();
 * 	Object value = propery.get("name");
 * @author 王真礼 日期 Jan 21, 2009
 *
 */
public class SysProperty {
	public static void main(String[] args) {
//		SecurityManager sm = System.getSecurityManager();
//		System.out.println(sm.getClass());
//		System.out.println(SysProperty.class.getClassLoader().getClass().getName());
		
		java.util.Properties pro = System.getProperties();
		String name = new String("name");
		System.out.println(pro.get(name));
		Enumeration<Object> keys = pro.keys();
		int i=0;
		while (keys.hasMoreElements()) {
			Object object = (Object) keys.nextElement();
			System.out.println("---- "+i+" -------------------------");
			System.out.println("Key:"+object+" \nValue:"+pro.get(object));
			i++;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?