JAVA -D命令選項

A JVM runs with a number of system properties. You can configure system properties by using the -D option, pronounced with an upper case 'D'

All you have to do i suse the -D flag, and provide the system prperty name immediately following the D, and equals sign, and then the value to be assigned to the property. For example, to set the file.encoding property of the Java runtime to utf-8, you could set the following property:

java -Dfile.encoding=utf-8

You can then grab the value programatically as follows:

System.getProperty("file.encoding"); /*this method is overloaded, as per previous post*/

System geProperty JavaDoc

Don't confuse the -D switch with the -d switch. Both are tested on the SCJA exam, but both do different things. Casing is important!

Some of the default properties that are supposed to have already been set include: file.encoding, file.separator, java.home and java.version.
相關文章
相關標籤/搜索