系統類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