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.