System.getProperty(String name, String def) :获取指定的系统属性,如果不存在该属性,则返回默认值def。 启动时可用-D属性名=属性值 来设置|覆盖系统熟悉
public class Main {
public static void main(String[] args) { //进入类文件 java -Dpwd=abc -cp . Main 可读取设置系统属性 String pwd = System.getProperty("pwd", "aaa") ; System.out.println(pwd); //System.out.println("Hello World!"); }
} 输出结果 abc
|