在Java中,可以通過System.setProperty()方法來設(shè)置系統(tǒng)參數(shù),通過命令行參數(shù)來設(shè)置運(yùn)行參數(shù)。
System.setProperty("myProperty", "myValue");
java -DmyProperty=myValue MyClass
在程序中可以通過System.getProperty()方法來獲取運(yùn)行參數(shù)的值,例如:
String value = System.getProperty("myProperty");