Recently I sorted out how Java can obtain relevant information about the operating system. The summary is as follows:
Java obtains the system parameter properties props = system. getproperties () through system. getproperties (); // system attribute
System. out. println ("Java Runtime Environment version:" + props. getproperty ("Java. version "); system. out. println ("Java Runtime Environment vendor:" + props. getproperty ("Java. vendor "); system. out. println ("Java vendor URL:" + props. getproperty ("Java. vendor. URL "); system. out. println ("Java installation path:" + props. getproperty ("Java. home "); system. out. println ("Java Virtual Machine Specification Version:" + props. getproperty ("Java. VM. specification. version "); system. out. println ("Java virtual machine specification Supplier:" + props. getproperty ("Java. VM. specification. vendor "); system. out. println ("Java virtual machine specification name:" + props. getproperty ("Java. VM. specification. name "); system. out. println ("Java Virtual Machine implementation version:" + props. getproperty ("Java. VM. version "); system. out. println ("Java Virtual Machine implementation vendor:" + props. getproperty ("Java. VM. vendor "); system. out. println ("Java Virtual Machine implementation name:" + props. getproperty ("Java. VM. name "); system. out. println ("Java Runtime Environment Standard Version:" + props. getproperty ("Java. specification. version "); system. out. println ("Java Runtime Environment specification Supplier:" + props. getproperty ("Java. specification. vender "); system. out. println ("Java Runtime Environment specification name:" + props. getproperty ("Java. specification. name "); system. out. println ("Java class format version:" + props. getproperty ("Java. class. version "); system. out. println ("Java class path:" + props. getproperty ("Java. class. path "); system. out. println ("List of paths searched during Database loading:" + props. getproperty ("Java. library. path "); system. out. println ("Default temporary file path:" + props. getproperty ("Java. io. tmpdir "); system. out. println ("path of one or more extended directories:" + props. getproperty ("Java. ext. dirs "); system. out. println ("operating system name:" + props. getproperty ("OS. name "); system. out. println ("Operating System Architecture:" + props. getproperty ("OS. arch "); system. out. println ("OS version:" + props. getproperty ("OS. version "); system. out. println ("file separator:" + props. getproperty ("file. separator "); // in UNIX system, it is"/"system. out. println ("path separator:" + props. getproperty ("path. separator "); //": "system. out. println ("line separator:" + props. getproperty ("line. separator "); //"/N "System in UNIX. out. println ("User Account name:" + props. getproperty ("user. name "); system. out. println ("Your home directory:" + props. getproperty ("user. home "); system. out. println ("current working directory of the User:" + props. getproperty ("user. dir "));
System. getproperty ("Sun. OS. Patch. Level"); // obtain the operating system version system. getproperty ("Sun. CPU. isalist"); // obtain the CPU system information.
Private inetaddress localhost = NULL; localhost = inetaddress. getlocalhost ();/*** local IP Address * @ return IP Address */Public String getip () {string IP = localhost. gethostaddress (); Return IP;}/*** get user machine name * @ return */Public String gethostname () {return localhost. gethostname ();}/*** get MAC address * @ return MAC address, for example: F0-4D-A2-39-24-A6 */Public String getmac () {networkinterface byinetaddress; try {byinetaddress = networkinterface. getbyinetaddress (localhost); byte [] hardwareaddress = byinetaddress. gethardwareaddress (); Return getmacfrombytes (hardwareaddress);} catch (socketexception e) {// todo auto-generated Catch Block E. printstacktrace ();} return NULL ;}