我在测试前,添加了一个环境变量,然后打印出所有的属性,没有发现该环境变量。所以我认为用
System.getProperty()得不到环境变量的值。但可以用java.class.path获得类路径。
public class GetClasspath { public GetClasspath() {
}
public static void main(String args[]){
Properties p = System.getProperties();
Iterator i = p.entrySet().iterator();
while (i.hasNext()) {
System.out.println(i.next());
} System.out.println(System.getProperties().get("java.class.path").toString());
}
}
System.getProperty()得不到环境变量的值。但可以用java.class.path获得类路径。
public class GetClasspath { public GetClasspath() {
}
public static void main(String args[]){
Properties p = System.getProperties();
Iterator i = p.entrySet().iterator();
while (i.hasNext()) {
System.out.println(i.next());
} System.out.println(System.getProperties().get("java.class.path").toString());
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货