1 回答

TA貢獻1876條經驗 獲得超7個贊
嘗試加載dll之前,需要將其放入庫路徑(推薦)。因此您將不得不從jar中提取它并將其復制到lib path中。
private void loadLib(String path, String name) {
name = System.mapLibraryName(name); // extends name with .dll, .so or .dylib
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = getClass().getResourceAsStream("/" + path + name);
File fileOut = new File("your lib path");
outputStream = new FileOutputStream(fileOut);
IOUtils.copy(inputStream, outputStream);
System.load(fileOut.toString());//loading goes here
} catch (Exception e) {
//handle
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
//log
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
//log
}
}
}
}
注意: ACWrapper是持有靜態方法的類
添加回答
舉報