File.delete () returns false

I created a file from my java programming, and I am logging some data using the Apache Commons registration API, in particular the Log4j implementation.

After the registration is complete, I set the link to the log class as null. When I now try to delete the file I was writing to, File.delete () returns false.

Deleting a file from Windows Explorer during debugging (at the moment immediately before calling File.delete ()), I get a notification “cannot delete: used by another program”.

There are no open file dependencies from my code (all threads are closed). The only object that can access the file is the log object, which I set to null before calling File.delete ()

Is there anyway that I can see which specific object holds the link to the file resource? Is there any other way to get a log object to free a resource by distinguishing it from zero? Can I force delete a file?

+3
source share
2 answers

Just setting the variable to null does not force the object to garbage collect. In addition, there is a possibility that it is registered in some kind of static map - you will need to check the implementation to be sure. (I think some versions use weak links, while others don't.)

, ? , File.deleteOnExit(), , , . ( , , deleteOnExit.)

, , ?

, - , ?

+5

- .


:

, log4js . , , . , false, .

org.apache.log4j.LogManager.shutdown();

, , , , .

close() Appender ( AppenderSkeleton), appenders getAllAppenders().

+3

All Articles