Java obtains information about the current operating system.
There are several mainstream methods, one is to use the following functions
Public static String getProperty (String key)
Key |
Description of related values |
Java. version |
Java. version Java Runtime Environment version |
Java. vendor |
Java. vendor Java Runtime Environment vendor |
Java. vendor. url |
Java. vendor. url URL of the Java vendor |
Java. home |
Java. home Java installation directory |
Java. vm. specification. version |
Java. vm. specification. version Java Virtual Machine standard version |
Java. vm. specification. vendor |
Java. vm. specification. vendor Java virtual machine specification vendor |
Java. vm. specification. name |
Java. vm. specification. name Java virtual machine specification name |
Java. vm. version |
Java. vm. version Java Virtual Machine implementation version |
Java. vm. vendor |
Java. vm. vendor Java Virtual Machine implementation vendor |
Java. vm. name |
Java. vm. name Java Virtual Machine implementation name |
Java. specification. version |
Java. specification. version Java Runtime Environment Standard version |
Java. specification. vendor |
Java. specification. vendor Java Runtime Environment specification vendor |
Java. specification. name |
Java. specification. name Java Runtime Environment Standard name |
Java. class. version |
Java. class. version Java class format version number |
Java. class. path |
Java. class. path Java class path |
Java. library. path |
List of paths searched when the java. library. path library is loaded |
Java. io. tmpdir |
Java. io. tmpdir default temporary file path |
Java. compiler |
Name of the JIT compiler to be used by java. compiler |
Java. ext. dirs |
Java. ext. dirs: path of one or more extension Directories |
OS. name |
OS. name of the Operating System |
OS. arch |
OS. arch Operating System Architecture |
OS. version |
OS. version |
File. separator |
File. separator file delimiter ("/" in UNIX) |
Path. separator |
Path. separator path separator (":" in UNIX systems) |
Line. separator |
Line. separator line separator ("/n" in UNIX ") |
User. name |
User. name: Account name of the user |
User. home |
User. home user's home directory |
User. dir |
Current working directory of user. dir |
One is to use the command line to obtain
Import java. io. bufferedReader; import java. io. inputStream; import java. io. inputStreamReader; import java.net. inetAddress; import java.net. networkInterface; import java. util. arrayList; import java. util. formatter; import java. util. list; import java. util. locale; import java. util. map; import java. util. properties; public class test {// obtain the computer configuration information (poor) by intercepting the cmd stream. public static List
GetIpAddress () {Process p = null; List
Address = new ArrayList
(); Try {p = new ProcessBuilder ("ipconfig", "/all "). start () ;} catch (Exception e) {return address;} StringBuffer sb = new StringBuffer (); // read the process output value InputStream inputStream = p. getInputStream (); BufferedReader br = new BufferedReader (new InputStreamReader (inputStream); String s = ""; try {while (s = br. readLine ())! = Null) {sb. append (s + "\ n") ;}} catch (Exception e) {e. printStackTrace ();} finally {try {inputStream. close ();} catch (Exception e) {e. printStackTrace () ;}} System. out. println (sb); return address;} public static void getIpconfig () {Map
Map = System. getenv (); System. out. println (map. get ("USERNAME"); // get the user name System. out. println (map. get ("COMPUTERNAME"); // obtain the computer name System. out. println (map. get ("USERDOMAIN"); // obtain the computer domain name} // obtain the computer ip address and mac address public static void getConfig () {try {InetAddress address = InetAddress. getLocalHost (); NetworkInterface ni = NetworkInterface. getByInetAddress (address); // ni. getInetAddresses (). nextElement (). getAddress (); Byte [] mac = ni. getHardwareAddress (); String sIP = address. getHostAddress (); String sMAC = ""; Formatter formatter = new Formatter (); for (int I = 0; I <mac. length; I ++) {sMAC = formatter. format (Locale. getDefault (), "% 02X % s", mac [I], (I <mac. length-1 )? "-":""). ToString ();} System. out. println ("IP:" + sIP); System. out. println ("MAC:" + sMAC);} catch (Exception e) {e. printStackTrace () ;}// obtain the computer's ip address, name, operating system name, operating system version public static void Config () {try {InetAddress addr = InetAddress. getLocalHost (); String ip = addr. getHostAddress (). toString (); // obtain the local ip String hostName = addr. getHostName (). toString (); // obtain the name of the local computer System. out. println ("local IP:" + ip + "\ n local name:" + hostName); Properties props = System. getProperties (); System. out. println ("operating system name:" + props. getProperty ("OS. name "); System. out. println ("OS version:" + props. getProperty ("OS. version ");} catch (Exception e) {e. printStackTrace () ;}// some other things, public static void all () {Properties props = System. getProperties (); 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 ");} public static void main (String [] args) {getConfig (); Config (); all ();}}