Java obtains information about the operating system.

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.