String getproperty (string key, string DEF) gets the system attribute described with the specified key. * If the key is the key of the configuration file such as the key system environment or properties, such as OS. name, return the value of the key * If the key is null or null, an error is returned! Key can't be empty key can't be null * If the key is not null, It is not null, or the key of the configuration file such as the system environment or properties, the def value is returned.
DEMO code:
Package COM. test; public class test {public static void main (string [] ARGs) {testsetgetproperty ();} public static void testsetgetproperty () {string str1, str2, str3; str1 = system. getproperty ("Java. version "); str2 = system. getproperty ("user. dir "); // str3 = system. getproperty (""); // The error key can't be empty system is returned. out. println (str2); system. out. println (str1);/* getproperty (string key, string DEF) gets the system genus described with the specified key * If the key of the configuration file such as the key system environment or properties, such as OS. Name, returns the value of the key * If the key is null or null, an error is returned! Key can't be empty key can't be null * If the key is not null, It is not null, or the key of the configuration file such as the system environment or properties, returns the def value **/string str4, str5, str6; str4 = system. getproperty ("OS. name "," mydefault "); // str5 = system. getproperty (null, "mydefault"); // The error key can't be null str6 = system. getproperty ("AAA", "mydefault"); // The output mydefault is not the system key of the configuration file such as the system environment or properties. out. println (str4); // output Windows 7 // system. out. println (str5); system. out. println (str6); // default output value: mydefault }}
Key-value pairs of configuration files such as system environment or properties
Java. Version |
Java Runtime Environment version |
Java. Vendor |
Java Runtime Environment vendor |
Java. Vendor. url |
Java vendor URL |
Java. Home |
Java installation directory |
Java. VM. Specification. Version |
Java Virtual Machine standard version |
Java. VM. Specification. Vendor |
Java virtual machine specification vendor |
Java. VM. Specification. Name |
Java virtual machine specification name |
Java. VM. Version |
Java Virtual Machine implementation version |
Java. VM. Vendor |
Java Virtual Machine implementation vendor |
Java. VM. Name |
Java Virtual Machine implementation name |
Java. Specification. Version |
Java Runtime Environment Standard version |
Java. Specification. Vendor |
Java Runtime Environment specification vendor |
Java. Specification. Name |
Java Runtime Environment specification name |
Java. Class. Version |
Java format version number |
Java. Class. Path |
Java class path |
Java. Library. Path |
List of search paths when the library is loaded |
Java. Io. tmpdir |
Default temporary file path |
Java. Compiler |
Name of the JIT compiler to be used |
Java. Ext. dirs |
Path of one or more extended Directories |
OS. Name |
Operating system name |
OS. Arch |
Operating System Architecture |
OS. Version |
Operating system version |
File. Separator |
File separator ("/" in UNIX) |
Path. Separator |
Path separator (":" in UNIX) |
Line. Separator |
Line separator ("/n" in UNIX ") |
User. Name |
User Account Name |
User. Home |
User's home directory |
User. dir |
Current working directory of the user |