Java System类loadLibrary()方法与示例
系統(tǒng)類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)的給定參數(shù)作為在該方法中傳遞的參數(shù)來加載庫。
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()方法來加載該庫。 在此方法中,以特定于系統(tǒng)的方式完成了從library_name到給定文件名的映射。 在類加載和實例化時,也將加載本機方法所需的已實現(xiàn)本機代碼。
loadLibrary() method is a static method, it is accessible with the class name too.
loadLibrary()方法是靜態(tài)方法,也可以使用類名進行訪問。
loadLibrary() method may throw an exception at the time of library loading:
在庫加載時, loadLibrary()方法可能會引發(fā)異常:
- 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):
參數(shù):
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 ,它不返回任何內(nèi)容。
Example:
例:
// Java program to demonstrate the example of // loadLibrary() method of System Classpublic 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
總結(jié)
以上是生活随笔為你收集整理的Java System类loadLibrary()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哈密顿路径_检查图形是否为哈密顿量(哈密
- 下一篇: Java OutputStreamWri