读书人

why temporary files can‘t be delete

发布时间: 2012-09-09 09:27:54 作者: rapoo

why temporary files can‘t be delete.

Temporary files are created by?java.io.File.createTempFile()?and marked with a flag?deleteOnExit(). As a result they are deleted by the system on application shutdown when all temporary files are closed. The application shutdown event is intercepted byRuntime.addShutdownHook().

Temporary files with JARs are not deleted on Windows platform if some resources (other than classes) are loaded from them usinggetResourceAsStream(). Temporary files with native libraries are never deleted on Windows platform. Attempt to explicitly delete these temporary files on shutdown by calling?File.delete()?fails because VM does not release these files' handles. See?Bug 4171239?"This occurs only on Win32, which does not allow a file to be deleted until all streams on it have been closed."

?

读书人网 >编程

热点推荐