最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java如何獲取主機(jī)的基本信息詳解

 更新時(shí)間:2021年12月26日 08:43:39   作者:小白  
最近遇到一個(gè)工作需求,上網(wǎng)查了一下怎樣在Java中獲取本機(jī)的ip和主機(jī)名,所以下面這篇文章主要給大家介紹了關(guān)于Java如何獲取主機(jī)的基本信息,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下

最近在做一個(gè)主機(jī)資源監(jiān)控的需求,首先是獲取一些最簡(jiǎn)單的基本參,像一些主機(jī)名稱、系統(tǒng)類型、ip、cpu、內(nèi)存和磁盤等等這些數(shù)據(jù),看起來雖然很簡(jiǎn)單,Java的基本庫(kù)就能完成,但是真的去使用的時(shí)候,還是有一些坑的。記錄一下,已備后用。

1. 獲取基本信息

1.1 獲取主機(jī)名稱和系統(tǒng)

主機(jī)名稱可以通過網(wǎng)絡(luò)類InetAddress來獲取,主機(jī)系統(tǒng)和用戶可以通過System類進(jìn)行獲取。

 public static void getLocalHost(){

     try{

         InetAddress ip = InetAddress.getLocalHost();

         String localName = ip.getHostName();

         String osName = System.getProperty("os.name");

         String userName = System.getProperty("user.name");

         String osVersion = System.getProperty("os.version");

         String osArch = System.getProperty("os.arch");

         

         System.out.println("當(dāng)前用戶:" + userName);

         System.out.println("用戶的主目錄:"+props.getProperty("user.home"));

         System.out.println("用戶的當(dāng)前工作目錄:"+props.getProperty("user.dir"));

         System.out.println("主機(jī)名稱:" + localName);

         System.out.println("主機(jī)系統(tǒng):" + osName);

         System.out.println("系統(tǒng)版本:" + osVersion);

         System.out.println("系統(tǒng)架構(gòu):" + osArch);

     } catch (Exception e) {

         e.printStackTrace();

     }

 }

1.2 獲取用戶信息

用戶信息都是使用System類進(jìn)行獲取。

 public static void getUserInfo(){

     try{

         String userName = System.getProperty("user.name");

         String userHome = System.getProperty("user.home");

         String userDir = System.getProperty("user.dir");

         

         System.out.println("當(dāng)前用戶:" + userName);

         System.out.println("用戶主目錄:"+ userHome);

         System.out.println("當(dāng)前工作目錄:"+ userDir);

     } catch (Exception e) {

         e.printStackTrace();

     }

 }

1.3 獲取主機(jī)IP等信息

主機(jī)的ip可以通過網(wǎng)絡(luò)類InetAddress進(jìn)行獲取,但是這個(gè)方法很玄學(xué),機(jī)器上多網(wǎng)卡還有虛擬機(jī)時(shí),獲取到就不準(zhǔn)確了。目前做的獲取的方法是痛毆便利網(wǎng)卡來獲取ip。因?yàn)楸闅v網(wǎng)卡來獲取ip要過濾一些不重要的網(wǎng)卡,過濾的方法是來自“經(jīng)驗(yàn)”的笨方法,可以借鑒,但不保證日后網(wǎng)卡條件復(fù)雜的情況下獲取不準(zhǔn)確。測(cè)試的是Linux、Mac和Windows系統(tǒng)可用。因?yàn)檫^濾條件不一樣,所以分為Windows獲取和非Windows獲取。

Windows系統(tǒng)獲取IP:

 public static void getWindowsIpAndMac(){

     try {

         Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();

         // 遍歷網(wǎng)卡接口

         while (allNetInterfaces.hasMoreElements()) {

             NetworkInterface netInterface = allNetInterfaces.nextElement();

             // 去除回環(huán)接口,子接口,未運(yùn)行和接口

             if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {

                 continue;

             }

             

             // 重點(diǎn)來了:“經(jīng)驗(yàn)”之談

             // 為了過濾掉虛擬機(jī)的網(wǎng)卡,可以通過網(wǎng)卡名來進(jìn)行基礎(chǔ)過濾。windows主機(jī)ip對(duì)應(yīng)的網(wǎng)卡名會(huì)包含下面三個(gè):Intel  無線、Realtek  網(wǎng)線、Ethernet  兼容xp系統(tǒng)

             if (!netInterface.getDisplayName().contains("Intel")

                 && !netInterface.getDisplayName().contains("Realtek")

                 && !netInterface.getDisplayName().contains("Ethernet")) {

                 continue;

             }

             

             String ip = "";

             String mac = "";

             String niName = "";

             Enumeration<InetAddress> addresses = netInterface.getInetAddresses();

             while (addresses.hasMoreElements()) {

                 InetAddress ia = addresses.nextElement();

                 // 去除本地回環(huán)地址,子接口,未運(yùn)行和地址

                 if (ia != null && !ia.isLoopbackAddress() && ia.isSiteLocalAddress() && !ia.isAnyLocalAddress()) {

                     // 判斷是否是ip v4地址

                     if (ia instanceof Inet4Address) {

                         ip = ia.getHostAddress();

                         // 獲取MAC地址

                         mac = getMac(ia);

                         niName = netInterface.getName();

                         if (StringUtils.isNotBlank(ip) && StringUtils.isNotBlank(mac) && StringUtils.isNotBlank(niName)){

                             System.out.println("當(dāng)前網(wǎng)卡:"+niName);

                             System.out.println("當(dāng)前主機(jī)ip:"+ip);

                             System.out.println("當(dāng)前主機(jī)MAC:"+mac);

                             return;

                         }

                     }

                 }

             }

         }

     } catch (SocketException e) {

         e.printStackTrace();

     }

 }

非Windows系統(tǒng)獲取IP:

其實(shí)和windows獲取的差不多,也是遍歷網(wǎng)卡然后進(jìn)行過濾,不過這個(gè)沒有“經(jīng)驗(yàn)”,不知道要過濾那些,所以用InetAddress進(jìn)行獲取,經(jīng)測(cè)試這個(gè)在非windows上獲取的還是準(zhǔn)確的(可能我linux網(wǎng)卡單一)。不過為了獲取當(dāng)前的網(wǎng)卡用了一個(gè)更笨的方法,既然當(dāng)前獲取的ip是準(zhǔn)確的,那就根據(jù)ip去獲取網(wǎng)卡。不過目前沒有找到這個(gè)方法,所以可以在遍歷網(wǎng)卡時(shí)取出符合當(dāng)前ip的網(wǎng)卡。(此方法在我這個(gè)需求里是可以的,不保證拿走就能用)。

 public static void getLinuxIpAndMac(AgentMonitor agentMonitor){

     try {

         // 先獲取ip

         InetAddress iad = InetAddress.getLocalHost();

         String localIp = iad.getHostAddress();

 ?

         // 遍歷網(wǎng)卡

         Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();

         while (allNetInterfaces.hasMoreElements()) {

             NetworkInterface netInterface = allNetInterfaces.nextElement();

             // 去除回環(huán)接口,子接口,未運(yùn)行和接口

             if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {

                 continue;

             }

 ?

             String ip = "";

             String mac = "";

             String niName = "";

             Enumeration<InetAddress> addresses = netInterface.getInetAddresses();

             while (addresses.hasMoreElements()) {

                 InetAddress ia = addresses.nextElement();

                 if (ia != null && !ia.isLoopbackAddress() && ia.isSiteLocalAddress() && !ia.isAnyLocalAddress()) {

                     // 判斷是否是ip v4地址且是否和已獲取的ip一致

                     if (ia instanceof Inet4Address && ia.getHostAddress().equals(localIp)) {

                         ip = ia.getHostAddress();

                         // 獲取MAC地址

                         mac = getMac(ia);

                         niName = netInterface.getName();

                         if (StringUtils.isNotBlank(ip) && StringUtils.isNotBlank(mac) && StringUtils.isNotBlank(niName)){

                             System.out.println("當(dāng)前網(wǎng)卡:"+niName);

                             System.out.println("當(dāng)前主機(jī)ip:"+ip);

                             System.out.println("當(dāng)前主機(jī)MAC:"+mac);

                             return;

                         }

                     }

                 }

             }

         }

 ?

     } catch (Exception e) {

         e.printStackTrace();

     }

 }

獲取MAC地址

 public static String getMac(InetAddress ia){

     try {

         //獲取網(wǎng)卡,獲取地址

         byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();

         StringBuffer sb = new StringBuffer();

         if (mac != null && mac.length>0){

             for(int i=0; i<mac.length; i++) {

                 if(i!=0) {

                     sb.append("-");

                 }

                 //字節(jié)轉(zhuǎn)換為整數(shù)

                 String str = Integer.toHexString(mac[i] & 0xff);

                 if(str.length()==1) {

                     sb.append("0").append(str);

                 }else {

                     sb.append(str);

                 }

             }

         }

         return sb.toString().toUpperCase();

     } catch (SocketException e) {

         e.printStackTrace();

         return null;

     }

 }

2. 獲取CPU信息

獲取CPU的信息這里選用的是oshi工具,經(jīng)測(cè)試這個(gè)獲取的還是比較準(zhǔn)確的,而且該工具還可以獲得其他硬件信息,能獲取到的還是比較全面的。首先需要引入oshi的依賴。

 <dependency>

     <groupId>com.github.oshi</groupId>

     <artifactId>oshi-core</artifactId>

     <version>3.12.2</version>

 </dependency>

oshi是依賴于JNA,需要導(dǎo)入jna和jna-platform我這里用的oshi是3.12.2版本,對(duì)應(yīng)使用的JNA的版本是5.2.0。springboot項(xiàng)目是自帶JNA的,如果不是springboot項(xiàng)目需要額外導(dǎo)入。如果springboot項(xiàng)目自帶的JNA版本過低,也需要額外導(dǎo)入高版本的JNA。

<dependency>

<groupId>net.java.dev.jna</groupId>

<artifactId>jna</artifactId>

<version>5.2.0</version>

</dependency>

JNA版本信息

2.1 獲取CPU核數(shù)

oshi中的CentralProcessor進(jìn)行獲取。獲取CPU物理可用的核數(shù),如果有開啟超頻,那么獲取的CPU核數(shù)可能會(huì)大于物理核數(shù)。

 public static void getCpuCount(){

     try {

         // 獲取SystemInfo實(shí)例

         SystemInfo systemInfo = new SystemInfo();

         // 獲取CentralProcessor實(shí)例

         CentralProcessor processor = systemInfo.getHardware().getProcessor();

         // 獲取CPU核數(shù)

         int cpuCount = processor.getLogicalProcessorCount();

         System.out.println("CPU核數(shù):"+cpuCount);

     } catch (SocketException e) {

         e.printStackTrace();

     }

 }

2.2 獲取CPU使用率

獲取系統(tǒng)范圍的CPU負(fù)載時(shí),一共獲取7個(gè)部分的負(fù)載。

  • CPU 空閑且系統(tǒng)沒有未完成的磁盤 I/O 請(qǐng)求的時(shí)間。
  • 在系統(tǒng)有未完成的磁盤 I/O 請(qǐng)求期間一個(gè)或多個(gè) CPU 空閑的時(shí)間。在windows不可用。在MacOS不可用。
  • CPU 用于服務(wù)硬件 IRQ 的時(shí)間。在MacOS不可用。
  • 在具有良好優(yōu)先級(jí)的用戶級(jí)別執(zhí)行時(shí)發(fā)生的 CPU 利用率。在windows不可用。
  • CPU 用于服務(wù)軟 IRQ 的時(shí)間。
  • 管理程序?qū)S糜谙到y(tǒng)中其他來賓的時(shí)間。
  • 在系統(tǒng)級(jí)別(內(nèi)核)執(zhí)行時(shí)發(fā)生的 CPU 利用率。
  • 在用戶級(jí)別(應(yīng)用程序)執(zhí)行時(shí)發(fā)生的 CPU 使用率。

要使用此方法計(jì)算總體空閑時(shí)間,就要包括上面所有部分,這樣計(jì)算出來的結(jié)果更準(zhǔn)確且兼容各種平臺(tái)。分兩次獲取上面信息,間隔1秒。這樣就能計(jì)算出1秒的CPU各方面使用的差值,通過每一項(xiàng)的差值除以總量,便可以得到每一項(xiàng)的CPU使用率。

通過下面方法還可以獲得CPU時(shí)間間隔內(nèi)的使用率和總使用率。

 public static void getCpuInfo() {

     try {

         SystemInfo systemInfo = new SystemInfo();

         CentralProcessor processor = systemInfo.getHardware().getProcessor();

         // 獲取系統(tǒng)范圍的cpu負(fù)載技計(jì)數(shù)

         long[] prevTicks = processor.getSystemCpuLoadTicks();

         // 睡眠1s

         TimeUnit.SECONDS.sleep(1);

         long[] ticks = processor.getSystemCpuLoadTicks();

         // 具有良好優(yōu)先級(jí)的用戶級(jí)別

         long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];

         // 硬件服務(wù)

         long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];

         // 軟服務(wù)使用

         long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];

         // 管理程序使用

         long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];

         // 系統(tǒng)使用

         long cSys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];

         // 用戶使用

         long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];

         // 等待使用

         long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];

         // 空閑使用

         long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];

         long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;

         double sysRate = cSys * 1.0 / totalCpu;

         double userRate = user * 1.0 / totalCpu;

         double waitRate = cSys * 1.0 / totalCpu;

         double idleRate = cSys * 1.0 / totalCpu;

         double betweenRate = processor.getSystemCpuLoadBetweenTicks();

         double cpuLoad = processor.getSystemCpuLoad();

         System.out.println("cpu系統(tǒng)使用率:" + new DecimalFormat("#.##%").format(sysRate));

         System.out.println("cpu用戶使用率:" + new DecimalFormat("#.##%").format(userRate));

         System.out.println("cpu當(dāng)前等待率:" + new DecimalFormat("#.##%").format(waitRate));

         System.out.println("cpu當(dāng)前空閑率:" + new DecimalFormat("#.##%").format(idleRate));

         // 獲取cpu最近(時(shí)間間隔內(nèi))使用率

         System.out.println("CPU load: "+ new DecimalFormat("#.##%").format(betweenRate) +"(counting ticks)");

         // 獲取cpu使用率

         System.out.println("CPU load: "+ new DecimalFormat("#.##%").format(cpuLoad) +"(OS MXBean)");

     }catch (Exception e){

         e.printStackTrace();

     }

 }

3. 獲取內(nèi)存信息

3.1 獲取主機(jī)內(nèi)存

獲取內(nèi)存信息可以使用OperatingSystemMXBean 來獲取。內(nèi)存信息可以獲取到的有內(nèi)存總量和可用內(nèi)存,通過這兩個(gè)值在計(jì)算出內(nèi)存已經(jīng)使用的量和內(nèi)存的使用率。獲取內(nèi)存信息同樣也可以使用oshi包中的SystemInfo類進(jìn)行獲取。但是測(cè)試時(shí)獲取的數(shù)據(jù)沒有OperatingSystemMXBean獲取的更精確。

 public static void getMemInfo(){

     try {

         OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

         // 總內(nèi)存,單位:字節(jié)

             long total = osmxb.getTotalPhysicalMemorySize();

             // 空閑內(nèi)存,單位:字節(jié)

             long free = osmxb.getFreePhysicalMemorySize();

             // 可用內(nèi)存,單位:字節(jié)

             long usable = osmxb.getFreePhysicalMemorySize();

             // 已使用內(nèi)存,單位:字節(jié)

             long used = total - free;

             // 內(nèi)存使用率

             double useRate = used * 1.0 / total;

             System.out.println("總共內(nèi)存:" + new DecimalFormat("#.##").format(total*1.0 / Math.pow(1024,3)) + "G");

             System.out.println("空閑內(nèi)存:" + new DecimalFormat("#.##").format(free*1.0 / Math.pow(1024,3)) + "G");

             System.out.println("已用內(nèi)存:" + new DecimalFormat("#.##").format(used*1.0 / Math.pow(1024,3)) + "G");

             System.out.println("可用內(nèi)存:" + new DecimalFormat("#.##").format(usable*1.0 / Math.pow(1024,3)) + "G");

             System.out.println("內(nèi)存使用率:" + new DecimalFormat("#.##%").format(useRate * 100.0));

 ?

     }catch (Exception e){

         e.printStackTrace();

     }

 }

3.2 獲取JVM內(nèi)存

獲取JVM的內(nèi)存信息需要使用MemoryMXBean接口中的MemoryUsage類。JVM信息主要是在系統(tǒng)運(yùn)行時(shí)對(duì)JVM的使用情況。包括初始的內(nèi)存大小、最大可用的內(nèi)存以及當(dāng)前已經(jīng)使用的內(nèi)存大小。

 public static void getJvmMemInfo(){

     try {

         MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

         // 椎內(nèi)存使用情況

         MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage();

         // jvm初始總內(nèi)存,單位:字節(jié)

         long initTotalMemorySize = memoryUsage.getInit();

         // jvm最大可用內(nèi)存,單位:字節(jié)

         long free = osmxb.getFreePhysicalMemorySize();

         // jvm已使用的內(nèi)存,單位:字節(jié)

         long usable = osmxb.getFreePhysicalMemorySize();

         

         System.out.println("jvm初始總內(nèi)存:" + new DecimalFormat("#.##").format(total*1.0 / Math.pow(1024,3)) + "G");

         System.out.println("jvm最大可用內(nèi)存:" + new DecimalFormat("#.##").format(free*1.0 / Math.pow(1024,3)) + "G");

         System.out.println("jvm已使用的內(nèi)存:" + new DecimalFormat("#.##").format(used*1.0 / Math.pow(1024,3)) + "G");

 ?

     }catch (Exception e){

         e.printStackTrace();

     }

 }

4. 獲取磁盤信息

獲取磁盤的使用情況用的是基礎(chǔ)的File類。首先是從根目錄遍歷所有磁盤信息,通過下面方法獲取磁盤信息。

  • file.getTotalSpace() :獲取當(dāng)前磁盤的總內(nèi)存
  • file.getFreeSpace() :獲取當(dāng)前磁盤的空閑內(nèi)存
  • file.getUsableSpace() :獲取當(dāng)前磁盤的可用內(nèi)存

通過上面獲取的三個(gè)參數(shù),可以計(jì)算磁盤總的已使用內(nèi)存和當(dāng)前磁盤的內(nèi)存使用率。

在計(jì)算每一個(gè)磁盤的信息時(shí),通過全局變量統(tǒng)計(jì)所有磁盤的信息總和,然后計(jì)算出主機(jī)總的磁盤內(nèi)存和使用率。

 /**

  * @param RADIX 內(nèi)存進(jìn)制大小,"經(jīng)驗(yàn)"之談是:Windows下進(jìn)制是1024,Mac和Linux是1000

  */

 public static void getDiskInfo(int RADIX){

     // 統(tǒng)計(jì)總內(nèi)存

     long total = 0;

     // 統(tǒng)計(jì)總空閑

     long free = 0;

     // 統(tǒng)計(jì)總可用

     long usable = 0;

     // 統(tǒng)計(jì)總已用

     long used = 0;

     // 磁盤總使用

     double usedRate = 0.0;

     try{

 ?

         File[] disks = File.listRoots();

         for (File file : disks){

             // 統(tǒng)計(jì)總量

             total += file.getTotalSpace();

             free += file.getFreeSpace();

             usable += file.getUsableSpace();

             used += file.getTotalSpace() - file.getFreeSpace();

             

             String diskPath = file.getPath();

             long diskTotal = file.getTotalSpace();

             long diskFree = file.getFreeSpace();

             long diskUsable = file.getUsableSpace();

             long diskUsed = diskTotal - diskFree;

             double diskUsedRate = diskUsed * 1.0 / diskTotal;

          

             System.out.println("磁盤路徑:" + diskPath);

             System.out.println("總共空間:"+ new DecimalFormat("#.##").format(diskTotal*1.0 / Math.pow(RADIX,3)) + "G");

             System.out.println("空閑空間:"+ new DecimalFormat("#.##").format(diskFree*1.0 / Math.pow(RADIX,3)) + "G");

             System.out.println("可用空間:"+ new DecimalFormat("#.##").format(diskUsable*1.0 / Math.pow(RADIX,3)) + "G");

             System.out.println("已用空間:"+ new DecimalFormat("#.##").format(diskUsed*1.0 / Math.pow(RADIX,3)) + "G");

             System.out.println("空間使用率:" + new DecimalFormat("#.##%").format(diskUsedRate*100));

             

         }

         

         String rootPath = "/";

         usedRate = used * 1.0 / total;

         

         System.out.println("磁盤根路徑:"+ rootPath);

         System.out.println("主機(jī)總共空間:"+ new DecimalFormat("#.##").format(total*1.0 / Math.pow(RADIX,3)) + "G");

         System.out.println("主機(jī)總空閑空間:"+ new DecimalFormat("#.##").format(free*1.0 / Math.pow(RADIX,3)) + "G");

         System.out.println("主機(jī)總可用空間:"+ new DecimalFormat("#.##").format(usable*1.0 / Math.pow(RADIX,3)) + "G");

         System.out.println("主機(jī)總已用空間:"+ new DecimalFormat("#.##").format(used*1.0 / Math.pow(RADIX,3)) + "G");

         System.out.println("主機(jī)總使用率:" + new DecimalFormat("#.##%").format(usedRate*100.0));

         

     }catch (Exception e){

         e.printStackTrace();

     }

 }

5. 獲取Java環(huán)境信息

這塊就是補(bǔ)充說明了,暫時(shí)沒用到,先保留一下,已備后用。

 public static void getJavaInfo(){

     Properties props=System.getProperties();

     System.out.println("Java的運(yùn)行環(huán)境版本:"+props.getProperty("java.version"));

     System.out.println("Java的運(yùn)行環(huán)境供應(yīng)商:"+props.getProperty("java.vendor"));

     System.out.println("Java供應(yīng)商的URL:"+props.getProperty("java.vendor.url"));

     System.out.println("Java的安裝路徑:"+props.getProperty("java.home"));

     System.out.println("Java的虛擬機(jī)規(guī)范版本:"+props.getProperty("java.vm.specification.version"));

     System.out.println("Java的虛擬機(jī)規(guī)范供應(yīng)商:"+props.getProperty("java.vm.specification.vendor"));

     System.out.println("Java的虛擬機(jī)規(guī)范名稱:"+props.getProperty("java.vm.specification.name"));

     System.out.println("Java的虛擬機(jī)實(shí)現(xiàn)版本:"+props.getProperty("java.vm.version"));

     System.out.println("Java的虛擬機(jī)實(shí)現(xiàn)供應(yīng)商:"+props.getProperty("java.vm.vendor"));

     System.out.println("Java的虛擬機(jī)實(shí)現(xiàn)名稱:"+props.getProperty("java.vm.name"));

     System.out.println("Java運(yùn)行時(shí)環(huán)境規(guī)范版本:"+props.getProperty("java.specification.version"));

     System.out.println("Java運(yùn)行時(shí)環(huán)境規(guī)范供應(yīng)商:"+props.getProperty("java.specification.vender"));

     System.out.println("Java運(yùn)行時(shí)環(huán)境規(guī)范名稱:"+props.getProperty("java.specification.name"));

     System.out.println("Java的類格式版本號(hào):"+props.getProperty("java.class.version"));

     System.out.println("Java的類路徑:"+props.getProperty("java.class.path"));

     System.out.println("加載庫(kù)時(shí)搜索的路徑列表:"+props.getProperty("java.library.path"));

     System.out.println("默認(rèn)的臨時(shí)文件路徑:"+props.getProperty("java.io.tmpdir"));

     System.out.println("一個(gè)或多個(gè)擴(kuò)展目錄的路徑:"+props.getProperty("java.ext.dirs"));

    

     System.out.println("文件分隔符:"+props.getProperty("file.separator"));//在 unix 系統(tǒng)中是"/" System.out.println("路徑分隔符:"+props.getProperty("path.separator"));//在 unix 系統(tǒng)中是":" System.out.println("行分隔符:"+props.getProperty("line.separator"));//在 unix 系統(tǒng)中是"/n" System.out.println("用戶的賬戶名稱:"+props.getProperty("user.name

 }

總結(jié)

到此這篇關(guān)于Java如何獲取主機(jī)的基本信息的文章就介紹到這了,更多相關(guān)Java獲取主機(jī)信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 一文盤點(diǎn)五種最常用的Java加密算法

    一文盤點(diǎn)五種最常用的Java加密算法

    大家平時(shí)的工作中,可能也在很多地方用到了加密、解密,比如:支付功能等,所以本文為大家盤點(diǎn)了Java中五個(gè)常用的加密算法,希望對(duì)大家有所幫助
    2023-06-06
  • Java中實(shí)現(xiàn)Comparator接口和用法實(shí)例(簡(jiǎn)明易懂)

    Java中實(shí)現(xiàn)Comparator接口和用法實(shí)例(簡(jiǎn)明易懂)

    這篇文章主要介紹了Java中實(shí)現(xiàn)Comparator接口和用法實(shí)例(簡(jiǎn)明易懂),本文給出實(shí)現(xiàn)Comparator接口的實(shí)例和使用這個(gè)接口的代碼實(shí)例,需要的朋友可以參考下
    2015-05-05
  • java垃圾回收原理之GC算法基礎(chǔ)

    java垃圾回收原理之GC算法基礎(chǔ)

    本章簡(jiǎn)要介紹GC的基本原理和相關(guān)技術(shù), 下一章節(jié)再詳細(xì)講解GC算法的具體實(shí)現(xiàn)。各種垃圾收集器的實(shí)現(xiàn)細(xì)節(jié)雖然并不相同,但總體而言,垃圾收集器都專注于兩件事情:查找所有存活對(duì)象,拋棄其他的部分,即死對(duì)象,不再使用的對(duì)象
    2022-01-01
  • 使用SQL保留兩位小數(shù)的實(shí)現(xiàn)方式

    使用SQL保留兩位小數(shù)的實(shí)現(xiàn)方式

    SQL中保留兩位小數(shù)有三種方法:1、使用ROUND()函數(shù)進(jìn)行四舍五入;2、使用CONVERT()函數(shù)和3、CAST()函數(shù)進(jìn)行強(qiáng)制類型轉(zhuǎn)換,這兩種方法會(huì)截?cái)喽嘤嗟奈粩?shù),ROUND()函數(shù)會(huì)保留0位,而CONVERT()和CAST()會(huì)刪除多余的0
    2024-11-11
  • Java字符串操作和C#字符串操作的不同小結(jié)

    Java字符串操作和C#字符串操作的不同小結(jié)

    在JAVA語(yǔ)言中,字符串?dāng)?shù)據(jù)實(shí)際上由String類所實(shí)現(xiàn)的。下面這篇文章主要給大家介紹了關(guān)于Java字符串操作和C#字符串操作的不同的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-12-12
  • ArrayList源碼探秘之Java動(dòng)態(tài)數(shù)組的實(shí)現(xiàn)

    ArrayList源碼探秘之Java動(dòng)態(tài)數(shù)組的實(shí)現(xiàn)

    這篇文章將帶大家從ArrayList源碼來探秘一下Java動(dòng)態(tài)數(shù)組的實(shí)現(xiàn),文中的示例代碼講解詳細(xì),對(duì)我們深入了解JavaScript有一定的幫助,需要的可以參考一下
    2023-08-08
  • Java中的邏輯控制語(yǔ)句詳解

    Java中的邏輯控制語(yǔ)句詳解

    下面小編就為大家?guī)硪黄狫ava邏輯控制的基礎(chǔ)文章。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2021-08-08
  • Mybatis實(shí)現(xiàn)批量操作8種小結(jié)

    Mybatis實(shí)現(xiàn)批量操作8種小結(jié)

    本文對(duì)Mybatis的五種批處理方式進(jìn)行了性能測(cè)試,包括批量新增和批量修改,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-10-10
  • GraalVM和Spring Native嘗鮮一步步讓Springboot啟動(dòng)飛起來66ms完成啟動(dòng)

    GraalVM和Spring Native嘗鮮一步步讓Springboot啟動(dòng)飛起來66ms完成啟動(dòng)

    GraalVM是高性能的JDK,支持Java/Python/JavaScript等語(yǔ)言,它可以讓Java變成二進(jìn)制文件來執(zhí)行,讓程序在任何地方運(yùn)行更快,這篇文章主要介紹了GraalVM和Spring Native嘗鮮一步步讓Springboot啟動(dòng)飛起來66ms完成啟動(dòng),需要的朋友可以參考下
    2023-02-02
  • Spring Boot攔截器實(shí)現(xiàn)步驟及測(cè)試實(shí)例

    Spring Boot攔截器實(shí)現(xiàn)步驟及測(cè)試實(shí)例

    這篇文章主要介紹了Spring Boot攔截器實(shí)現(xiàn)步驟及測(cè)試實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04

最新評(píng)論

醴陵市| 武邑县| 桃园市| 商河县| 顺义区| 湘潭县| 淮滨县| 滨州市| 建湖县| 北海市| 无极县| 方山县| 马鞍山市| 新建县| 綦江县| 高邮市| 广饶县| 巧家县| 和林格尔县| 乐安县| 沾化县| 金坛市| 陆河县| 客服| 太湖县| 西华县| 衡山县| 内黄县| 天等县| 渝北区| 永福县| 金坛市| 平顺县| 永胜县| 道孚县| 东平县| 巴彦县| 博乐市| 会同县| 葵青区| 菏泽市|