Java System类loadLibrary()方法与示例

系统类loadLibrary()方法 (System class loadLibrary() method)

  • loadLibrary() method is available in java.lang package.

    loadLibrary()方法在java.lang包中可用。

  • loadLibrary() method is used to load the library with the given parameter named library_name(library name) as an argument passed in the method.

    loadLibrary()方法用于使用名为library_name(library name)的给定参数作为在该方法中传递的参数来加载库。

  • A java file may contain native code for that we need to load the library by using loadLibrary() method. In this method, the mapping from a library_name to a given file name is done in a system-specific manner. At the time of class loading and instantiating, the required implemented native code for the native methods will then be loaded as well.

    一个Java文件可能包含本机代码,我们需要使用loadLibrary()方法来加载该库。 在此方法中,以特定于系统的方式完成了从library_name到给定文件名的映射。 在类加载和实例化时,也将加载本机方法所需的已实现本机代码。

  • loadLibrary() method is a static method, it is accessible with the class name too.

    loadLibrary()方法是静态方法,也可以使用类名进行访问。

  • loadLibrary() method may throw an exception at the time of library loading:

    在库加载时, loadLibrary()方法可能会引发异常:

    • SecurityException: In this exception, its checkLink() method does not allow load the specified library as passed in the method when the security manager exists.SecurityException :在此异常中,当安全管理器存在时,其checkLink()方法不允许加载在方法中传递的指定库。
    • UnsatisfiedLinkError: In this exception, if the loaded library does not exists.UnsatisfiedLinkError :在这种情况下,如果加载的库不存在。
    • NullPointerException: In this exception, if the loaded library is null.NullPointerException :在此异常中,如果加载的库为null。

Syntax:

句法:

    public static void loadLibrary(String library_name);

Parameter(s):

参数:

  • String library_name – represents the name of the library.

    字符串library_name –代表库的名称。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回类型为void ,它不返回任何内容。

Example:

例:

// Java program to demonstrate the example of 
// loadLibrary() method of System Class

public class LoadLibraryMethod {
    public static void main(String[] args) {
        // load a library FP30TXT.dll that is in Windows/system folder*/
        System.out.println(" Process of Library Loading ");
        Runtime.getRuntime().loadLibrary("C:/Windows/system/FP30TXT.dll");
        System.out.println("Process of Library Loading  completion");
    }
}

Output

输出量

E:\Programs>javac LoadLibraryMethod.java
E:\Programs>java LoadLibraryMethod
Process of Library Loading
Process of Library Loading completion


翻译自: https://www.includehelp.com/java/system-class-loadlibrary-method-with-example.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值