【发布时间】:2016-04-03 02:49:05
【问题描述】:
我有一个项目,其资源目录与此类似:
[Project]
[java]
MainClass
...
...
[resources]
MyDll.dll
我希望能够使用System.load() 加载MyDll.dll。我读到能够从 jar 中执行此操作,我需要首先将 dll 提取到临时位置。我目前正在使用此代码:
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();
}
但是,我认为它没有找到文件。 input 始终是 null。有没有办法在资源文件夹中找到MyDll.dll?
【问题讨论】: