I'm trying to load a dll file from a jar to work with the applet with this fix:
I create the file, set it writable and executable, but when I check it with canWrite()/canExecute() it returns false. The applet is signed.
The code:
private static void loadLib() {
URL res = SystemActivityNotifications.class.getResource("/sys-native
/sysactivitynotifications.dll");
InputStream in = res.openStream();
File dll = new File(path + "sysactivitynotifications.dll");
dll.setExecutable(true);
dll.setWritable(true);
logger.info(dll.canWrite() + " " + dll.canExecute());
FileOutputStream fos = new FileOutputStream(dll);
byte[] array = new byte[1024];
try {
for(int i = in.read(array); i != 1; i=in.read(array)) {
fos.write(array, 0, i);
}
} catch (IOException e) { logger.info("Cannot write to file: " + e.getMessage()); }
fos.close();
in.close();
System.load(dll.getAbsolutePath());
}
The file is created properly, but it throws an exception while trying to write to it.
edit: it writes to the file the second time I run the applet, but if I delete the file and run again the first iteration doesn't work.
Forgot to mention: all the code above is from a catch block after System.load.library(dll); throws the exception.
try
{
System.loadLibrary("sysactivitynotifications");
ptr = allocAndInit();
if (ptr == -1)
ptr = 0;
}
catch (Throwable t)
{
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
else {
loadLib();
}
}
Edit: it throws me this error:
java.lang.UnsatisfiedLinkError: C:\: The process cannot access the file because it is being used by another process