Java System mapLibraryName() 方法



描述

Java System mapLibraryName() 方法將庫名稱對映到表示本地庫的特定於平臺的字串。

宣告

以下是 java.lang.System.mapLibraryName() 方法的宣告

public static String mapLibraryName(String libname)

引數

libname - 這是庫的名稱。

返回值

此方法返回特定於平臺的本地庫名稱。

異常

NullPointerException - 如果 libname 為 null

示例:為作業系統名稱對映庫名稱

以下示例演示了 Java System mapLibraryName() 方法的使用。在此程式中,我們使用“os.name”鍵檢索了作業系統名稱,然後使用 mapLibraryName() 列印相應的對映庫。

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {

      // prints the name of the Operating System
      System.out.println(System.getProperty("os.name"));

      /* maps a library name into a platform-specific string representing
         a native library */
      String str = System.mapLibraryName("os.name");   
      System.out.println(str);
   }
} 

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Windows 11
os.name.dll

示例:為使用者目錄對映庫名稱

以下示例演示了 Java System mapLibraryName() 方法的使用。在此程式中,我們使用“user.dir”鍵檢索了使用者目錄名稱,然後使用 mapLibraryName() 列印相應的對映庫。

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {

      // prints the name of the User Directory
      System.out.println(System.getProperty("user.dir"));

      /* maps a library name into a platform-specific string representing
         a native library */
      String str = System.mapLibraryName("user.dir");   
      System.out.println(str);
   }
} 

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

C:\Users\Tutorialspoint\eclipse-workspace\Tutorialspoint
user.dir.dll

示例:為 Java 版本對映庫名稱

以下示例演示了 Java System mapLibraryName() 方法的使用。在此程式中,我們使用“java.runtime.version”鍵檢索了使用者目錄名稱,然後使用 mapLibraryName() 列印相應的對映庫。

package com.tutorialspoint;

public class SystemDemo {

   public static void main(String[] args) {

      // prints the name of the User Directory
      System.out.println(System.getProperty("java.runtime.version"));

      /* maps a library name into a platform-specific string representing
         a native library */
      String str = System.mapLibraryName("java.runtime.version");   
      System.out.println(str);
   }
} 

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

21.0.2+13-LTS-58
java.runtime.version.dll
java_lang_system.htm
廣告

© . All rights reserved.