黑马程序员技术交流社区

标题: System.getProperty的问题 [打印本页]

作者: 章闽    时间: 2012-10-22 19:04
标题: System.getProperty的问题
public class test {

public static void main(String[] args) {
System.out.println(System.getProperty( "test.initscript"));
System.out.println(System.getProperty( "java.version"));
  }
}
the result is:
null
1.6.0_30

如何自己设置一个系统非默认的property,如test.initscript="123456",
使上面的程序输出结果为:
123456
1.6.0_30



作者: 于连林    时间: 2012-10-22 19:18
这个好像都是随虚拟机加载而加载的吧,比如下面那个获得Java 运行时环境版本
这个都是不能改的吧
作者: 吴兵    时间: 2012-10-22 19:39
  1. public class Test
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 //setProperty(String key, String value)设置指定键指示的系统属性
  6.                 System.setProperty("initscript","123456");
  7.                
  8.                 System.out.println(System.getProperty("initscript"));
  9.                 System.out.println(System.getProperty( "java.version"));
  10.          }
  11. }
复制代码

作者: qhasilver    时间: 2012-10-22 19:42

  1. public class test {
  2. public static void main(String[] args) {
  3.                 System.setProperty("test.initscript", "123456");//设置自定义property
  4.                 System.out.println(System.getProperty( "test.initscript"));//输出自定义property
  5.                 System.out.println(System.getProperty( "java.version"));
  6.   }
  7. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2