依存している 2 つの .dll ファイルを持つ .jar があります。実行時にこれらのファイルを .jar 内からユーザーの一時フォルダーにコピーする方法があるかどうかを知りたいです。これが私が持っている現在のコードです(質問のサイズを減らすために.dllを1つだけロードするように編集しました):
public String tempDir = System.getProperty("java.io.tmpdir");
public String workingDir = dllInstall.class.getProtectionDomain().getCodeSource().getLocation().getPath();
public boolean installDLL() throws UnsupportedEncodingException {
try {
String decodedPath = URLDecoder.decode(workingDir, "UTF-8");
InputStream fileInStream = null;
OutputStream fileOutStream = null;
File fileIn = new File(decodedPath + "\\loadAtRuntime.dll");
File fileOut = new File(tempDir + "loadAtRuntime.dll");
fileInStream = new FileInputStream(fileIn);
fileOutStream = new FileOutputStream(fileOut);
byte[] bufferJNI = new byte[8192000013370000];
int lengthFileIn;
while ((lengthFileIn = fileInStream.read(bufferJNI)) > 0) {
fileOutStream.write(bufferJNI, 0, lengthFileIn);
}
//close all steams
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (UnsupportedEncodingException e) {
System.out.println(e);
return false;
}
私の主な問題は、実行時に .dll ファイルを jar から取り出すことです。.jar 内からパスを取得する方法は役に立ちます。
前もって感謝します。