这是一个奇怪的随机错误,有时会在Windows 7和Windows 8上显示出来。一切都很好,然后当Java尝试访问临时文件夹中的DLL时突然出现拒绝访问异常。
我发现删除TEMP文件夹并让它自动重新创建它通常可以解决问题。
如果您是将该DLL放入TEMP文件夹的代码的作者,那么我会建议您更改将该DLL放在此路径下的文件夹中的代码,因为我尚未在此处看到此问题:% USERPROFILE%\ AppData \ Local \
我在某处读到这可能是由Microsoft Security Essentials引起的,但它看起来并不像刚安装在遇到此问题的计算机上。
我见过这种情况发生在许多不同的DLL文件,如jna.dll。
如果您使用JNA并且存在此问题,则可以更改临时目录系统属性,并且JNA将在不同的目录中创建该文件。此代码应该为此工作。
String osName = System.getProperty("os.name");
if (osName.toLowerCase().startsWith("windows")) {
// we change the temp directory because sometimes Windows is stupid and doesn't want to load jna.dll from the temp directory
File tempDir = new File(System.getenv("USERPROFILE") + "\\AppData\\Local\\MyCompany\\temp");
System.out.println("Using temp dir: " + tempDir.getPath());
tempDir.mkdirs();
System.setProperty("java.io.tmpdir", tempDir.getPath());
}
是的,谢谢我会试试这个 – kelvz 2014-02-28 09:14:31