简体   繁体   English

临时文件不会在退出时删除-这是为什么?

[英]Temp file won't delete on exit - why is this?

I am trying to delete these temp files on exit: - "hsperfdata_user" - "JNativeHook-2.1.0" - "jna-196922" 我正在尝试在退出时删除以下临时文件:-“ hsperfdata_user”-“ JNativeHook-2.1.0”-“ jna-196922”

It doesn't appear that they are deleting! 看来他们没有删除!

if (temp != null) {
    for (File file : temp.listFiles()) {
        if (file.getName().contains("JNative") || file.getName().contains("rar") || file.getName().contains("hsper") || file.getName().contains("jna") || file.getName().contains("dll")) {
            file.deleteOnExit();
            System.out.println(file.getName());
        }
    }
}

The "duplicate" question refers to deleting files that you have created - I haven't created these temp. “重复”问题是指删除您创建的文件-我尚未创建这些临时文件。 files deliberately. 文件是故意的。 They create automatically. 它们自动创建。

It's not possible on Windows because the DLL is still loaded into the VM when it tries to delete itself. 在Windows上这是不可能的,因为在尝试删除自身时DLL仍会加载到VM中。 If it's a problem, the file should be permanently unpacked to the installation location and the appropriate java.library.path set. 如果有问题,则应将文件永久解压缩到安装位置并设置适当的java.library.path I would like to reiterate that this is not possible because java does not provide an System.unload(...) method to remove the library from the JVM safely due to technical restriction. 我想重申一下这是不可能的,因为由于技术限制,java没有提供System.unload(...)方法来安全地从JVM中删除该库。

It maybe possible: https://github.com/kwhat/jnativehook/issues/148#issuecomment-282173982 可能是这样: https : //github.com/kwhat/jnativehook/issues/148#issuecomment-282173982

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM