Kai*_*aan 8 java dll file-io java-native-interface jar
我有一个已签名的applet,我想写出包含在我启动applet的jar中的dll文件.
我这样做是因为我想在dll上做一个System.load,因为显然你无法从applet中的jar内部加载DLL.
第二个问题是如果你可以在applet中添加环境变量 - 例如我想将我的DLL提取到硬盘驱动器的位置并添加环境变量,以便System.load可以找到它.
您应该能够通过以下方式实现此目的:
.dll
从applet jar中提取到系统临时目录中.System.load(..)
使用提取的文件调用AccessController
.这种方法可以避免设置环境变量的需要.这是一些示例代码:
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
String dllName = "my.dll";
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File tmpFile = new File(tmpDir, dllName);
try {
InputStream in = getClass().getResourceAsStream(dllName);
OutputStream out = new FileOutputStream(tmpFile);
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.load(tmpFile.getAbsolutePath());
} catch (Exception e) {
// deal with exception
}
return null;
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2973 次 |
最近记录: |