I have a project set up with a resources directory similar to this:
[Project]
[java]
MainClass
...
...
[resources]
MyDll.dll
I want to be able to load MyDll.dll
using System.load()
. I read that to be able to do this from the jar, I need to first extract the dll to a temporary location. I am currently using this code to do so:
try {
InputStream input = this.class.getResourceAsStream("MyDll.dll");
byte[] buffer = new byte[1024];
int read = -1;
File temp = File.createTempFile("MyDll.dll", "");
FileOutputStream output = new FileOutputStream(temp);
while ((read = input.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.close();
input.close();
System.load(temp.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
However, I think it's not finding the file. input
is always null
. Is there a way I can locate MyDll.dll
in the resources folder?